home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / ck5a189s / ckuus4.c < prev    next >
C/C++ Source or Header  |  1993-07-05  |  81KB  |  2,846 lines

  1. #ifndef NOICP
  2.  
  3. /*  C K U U S 4 --  "User Interface" for Unix Kermit, part 4  */
  4.  
  5. /*
  6.   Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET),
  7.   Columbia University Academic Information Systems, New York City.
  8.  
  9.   Copyright (C) 1985, 1993, Trustees of Columbia University in the City of New
  10.   York.  The C-Kermit software may not be, in whole or in part, licensed or
  11.   sold for profit as a software product itself, nor may it be included in or
  12.   distributed with commercial products or otherwise distributed by commercial
  13.   concerns to their clients or customers without written permission of the
  14.   Office of Kermit Development and Distribution, Columbia University.  This
  15.   copyright notice must not be removed, altered, or obscured.
  16. */
  17.  
  18. /*
  19.   File ckuus4.c -- Functions moved from other ckuus*.c modules to even
  20.   out their sizes.
  21. */
  22. #include "ckcdeb.h"
  23. #include "ckcasc.h"
  24. #include "ckcker.h"
  25. #include "ckuusr.h"
  26. #include "ckuver.h"
  27. #include "ckcnet.h"            /* Network symbols */
  28.  
  29. #ifndef NOCSETS                /* Character sets */
  30. #include "ckcxla.h"
  31. #endif /* NOCSETS */
  32.  
  33. #ifndef AMIGA
  34. #ifndef MAC
  35. #include <signal.h>
  36. #include <setjmp.h>
  37. #endif /* MAC */
  38. #endif /* AMIGA */
  39.  
  40. #ifdef SUNX25
  41. extern int revcall, closgr, cudata, npadx3;
  42. int x25ver;
  43. extern char udata[MAXCUDATA];
  44. extern CHAR padparms[MAXPADPARMS+1];
  45. extern struct keytab padx3tab[];
  46. #endif /* SUNX25 */
  47.  
  48. #ifdef NETCONN
  49. extern char ipaddr[];
  50. #ifdef TNCODE
  51. extern int tn_duplex, tn_nlm;
  52. extern char *tn_term;
  53. #endif /* TNCODE */
  54. #endif /* NETCONN */
  55.  
  56. #ifndef NOSPL
  57. /* This needs to be internationalized... */
  58. static
  59. char *months[] = {
  60.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  61.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  62. };
  63.  
  64. static
  65. char *wkdays[] = {
  66.     "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  67. };
  68. #endif /* NOSPL */
  69.  
  70. #ifdef UNIX
  71. extern int ttyfd;
  72. #endif /* UNIX */
  73. #ifdef OS2
  74. extern int ttyfd;
  75. #endif /* OS2 */
  76.  
  77. _PROTOTYP( static VOID shods, (char *) );
  78.  
  79. extern struct keytab colxtab[];
  80.  
  81. extern CHAR
  82.   eol, mypadc, mystch, padch, seol, stchr;
  83.  
  84. extern char
  85.   kermrc[], ttname[],
  86.   *ckxsys, *versio, **xargv, *zinptr;
  87.  
  88. extern int
  89.   atcapr, autopar, bctr, bctu, bgset, bigrbsiz, bigsbsiz, binary, carrier,
  90.   cdtimo, cmask, crunched, delay, duplex, ebq, ebqflg, escape, flow, fmask,
  91.   fncact, fncnv, inecho, keep, local, lscapr, lscapu,
  92.   maxrps, maxsps, maxtry, mdmspd, mdmtyp, mypadn, ncolx,
  93.   nettype, network, nmac, noinit, npad, parity, pktlog, pkttim, rcflag,
  94.   retrans, rpackets, rptflg, rptq, rtimo, seslog, sessft, sosi, spackets,
  95.   spsiz, spsizf, spsizr, srvtim, stayflg, success, timeouts, tralog,
  96.   tsecs, ttnproto, turn, turnch, urpsiz, wmax, wslotn, wslotr, xargc, xargs,
  97.   zincnt, fdispla, tlevel, xitsta, spmax, insilence, cmdmsk, timint, timef;
  98.  
  99. #ifdef VMS
  100.   extern int frecl;
  101. #endif /* VMS */
  102.  
  103. extern long
  104.   ffc, filcnt, rptn, speed, tfc, tlci, tlco, vernum;
  105.  
  106. #ifndef NOSPL
  107. extern char fspec[], myhost[];
  108. #endif /* NOSPL */
  109.  
  110. extern char *tfnam[];            /* Command file names */
  111.  
  112. #ifdef DCMDBUF
  113. extern struct cmdptr *cmdstk;
  114. extern char *line;
  115. #else
  116. extern struct cmdptr cmdstk[];
  117. extern char line[];
  118. #endif /* DCMDBUF */
  119.  
  120. extern char pktfil[],            /* Packet log file name */
  121. #ifdef DEBUG
  122.   debfil[],                /* Debug log file name */
  123. #endif /* DEBUG */
  124. #ifdef TLOG
  125.   trafil[],                /* Transaction log file name */
  126. #endif /* TLOG */
  127.   sesfil[];                /* Session log file name */
  128.  
  129. #ifndef NOXMIT                /* TRANSMIT command variables */
  130. extern char xmitbuf[];
  131. extern int xmitf, xmitl, xmitp, xmitx, xmits, xmitw;
  132. #endif /* NOXMIT */
  133.  
  134. #ifndef NOSPL
  135. /* Script programming language items */
  136. extern char **a_ptr[];            /* Arrays */
  137. extern int a_dim[];
  138. extern char inpbuf[], inchar[];        /* Buffers for INPUT and REINPUT */
  139. extern char *inpbp;            /* And pointer to same */
  140. static char *inpbps = inpbuf;        /* And another */
  141. extern int incount;            /* INPUT character count */
  142. extern int maclvl;            /* Macro invocation level */
  143. extern struct mtab *mactab;        /* Macro table */
  144. extern char *mrval[];
  145. extern int macargc[], cmdlvl;
  146. extern char *m_arg[MACLEVEL][10]; /* You have to put in the dimensions */
  147. extern char *g_var[GVARS];      /* for external 2-dimensional arrays. */
  148. #ifdef DCMDBUF
  149. extern int *count, *inpcas;
  150. #else
  151. extern int count[], inpcas[];
  152. #endif /* DCMDBUF */
  153. #endif /* NOSPL */
  154.  
  155. #ifdef UNIX
  156. extern int haslock;            /* For UUCP locks */
  157. extern char flfnam[];
  158. extern int maxnam, maxpath;        /* Longest name, path length */
  159. #endif /* UNIX */
  160.  
  161. #ifndef NODIAL
  162. /* DIAL-related variables */
  163. extern int nmdm, dialhng, dialtmo, dialksp, dialdpy, dialmnp, dialmhu;
  164. extern char *dialnum, *dialdir, *dialnpr;
  165. extern struct keytab mdmtab[];
  166. #endif /* NODIAL */
  167.  
  168. #ifndef NOCSETS
  169. /* Translation stuff */
  170. extern int fcharset, tcharset, tslevel, language, nlng, tcsr, tcsl;
  171. extern struct keytab lngtab[];
  172. extern struct csinfo fcsinfo[], tcsinfo[];
  173. extern struct langinfo langs[];
  174. #ifdef CK_ANSIC
  175. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */
  176. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */
  177. #else
  178. extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])();    /* Character set */
  179. extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])();    /* translation functions. */
  180. #endif /* CK_ANSIC */
  181. #endif /* NOCSETS */
  182.  
  183. #ifndef NOSPL
  184. /* Built-in variable names, maximum length VNAML (20 characters) */
  185.  
  186. struct keytab vartab[] = {
  187.     "argc",      VN_ARGC,  0,
  188.     "args",      VN_ARGS,  0,
  189.     "cmdfile",   VN_CMDF,  0,
  190.     "cmdlevel",  VN_CMDL,  0,
  191.     "cmdsource", VN_CMDS,  0,
  192.     "count",     VN_COUN,  0,
  193.     "cpu",     VN_CPU,   0,
  194.     "date",      VN_DATE,  0,
  195.     "day",       VN_DAY,   0,        /* Edit 181 */
  196.     "directory", VN_DIRE,  0,
  197.     "exitstatus",VN_EXIT,  0,
  198.     "filespec",  VN_FILE,  0,
  199.     "fsize",     VN_FFC,   0,
  200.     "home",      VN_HOME,  0,
  201.     "host",      VN_HOST,  0,
  202.     "input",     VN_IBUF,  0,
  203.     "inchar",    VN_ICHR,  0,
  204.     "incount",   VN_ICNT,  0,
  205.     "line",      VN_LINE,  0,
  206.     "local",     VN_LCL,   0,
  207.     "macro",     VN_MAC,   0,
  208.     "ndate",     VN_NDAT,  0,
  209.     "nday",      VN_NDAY,  0,
  210.     "ntime",     VN_NTIM,  0,
  211.     "platform",  VN_SYSV,  0,
  212.     "program",   VN_PROG,  0,
  213.     "return",    VN_RET,   0,
  214.     "speed",     VN_SPEE,  0,
  215.     "status",    VN_SUCC,  0,
  216.     "system",    VN_SYST,  0,
  217.     "tfsize",    VN_TFC,   0,
  218.     "time",      VN_TIME,  0,
  219. #ifdef UNIX
  220.     "ttyfd",     VN_TTYF,  0,
  221. #endif /* UNIX */
  222. #ifdef OS2
  223.     "ttyfd",     VN_TTYF,  0,
  224. #endif /* OS2 */
  225.     "version",   VN_VERS,  0
  226. };
  227. int nvars = (sizeof(vartab) / sizeof(struct keytab));
  228. #endif /* NOSPL */
  229.  
  230. #ifndef NOSPL
  231. struct keytab fnctab[] = {        /* Function names */
  232.     "character",  FN_CHR, 0,        /* Character from code */
  233.     "code",       FN_COD, 0,        /* Code from character */
  234.     "contents",   FN_CON, 0,        /* Definition (contents) of variable */
  235.     "definition", FN_DEF, 0,        /* Return definition of given macro */
  236.     "evaluate",   FN_EVA, 0,        /* Evaluate given arith expression */
  237.     "execute",    FN_EXE, 0,        /* Execute given macro */
  238.     "files",      FN_FC,  0,        /* File count */
  239.     "index",      FN_IND, 0,        /* Index (string search) */
  240.     "length",     FN_LEN, 0,        /* Return length of argument */
  241.     "literal",    FN_LIT, 0,        /* Return argument literally */
  242.     "lower",      FN_LOW, 0,        /* Return lowercased argument */
  243.     "lpad",       FN_LPA, 0,        /* Return left-padded argument */
  244.     "maximum",    FN_MAX, 0,        /* Return maximum of two arguments */
  245.     "minimim",    FN_MIN, 0,        /* Return minimum of two arguments */
  246. #ifdef COMMENT
  247. /* not needed because \feval() has it */
  248.     "modulus",    FN_MOD, 0,        /* Return modulus of two arguments */
  249. #endif /* COMMENT */
  250.     "nextfile",   FN_FIL, 0,        /* Next file in list */
  251.     "rep",        FN_REP, CM_INV|CM_ABR,
  252.     "repeat",     FN_REP, 0,        /* Repeat argument given # of times */
  253.     "replace",    FN_RPL, 0,        /* Replace string1 with string2 */
  254. #ifndef NOFRILLS
  255.     "reverse",    FN_REV, 0,        /* Reverse the argument string */
  256. #endif /* NOFRILLS */
  257.     "right",      FN_RIG, 0,        /* Rightmost n characters */
  258.     "rpad",       FN_RPA, 0,        /* Right-pad the argument */
  259.     "substring",  FN_SUB, 0,        /* Extract substring from argument */
  260.     "upper",      FN_UPP, 0        /* Return uppercased argument */
  261. };
  262. int nfuncs = (sizeof(fnctab) / sizeof(struct keytab));
  263. #endif /* NOSPL */
  264.  
  265. #ifndef NOSPL                /* Buffer for expansion of */
  266. #define VVBUFL 65            /* built-in variables. */
  267. char vvbuf[VVBUFL];
  268. #endif /* NOSPL */
  269.  
  270. struct keytab disptb[] = {        /* Log file disposition */
  271.     "append",    1,  0,
  272.     "new",       0,  0
  273. };
  274.  
  275. /*  P R E S C A N -- Quick look thru command-line args for init file name */
  276. /*  Also for -d (debug), -z (force foreground), -S (stay) */
  277.  
  278. VOID
  279. prescan() {
  280.     int yargc; char **yargv;
  281.     char x;
  282.  
  283.     yargc = xargc;
  284.     yargv = xargv;
  285.     strcpy(kermrc,KERMRC);        /* Default init file name */
  286. #ifndef NOCMDL
  287.     while (--yargc > 0) {        /* Look for -y on command line */
  288.     yargv++;
  289.     if (**yargv == '-') {        /* Option starting with dash */
  290.         x = *(*yargv+1);        /* Get option letter */
  291.         if (x == 'Y') {        /* Is it Y (= no init file?) */
  292.         noinit = 1;
  293.         continue;
  294.         } else if (x == 'y') {    /* Is it y? */
  295.         yargv++, yargc--;    /* Yes, count and check argument */
  296.         if (yargc < 1) fatal("missing name in -y");
  297.         strcpy(kermrc,*yargv);    /* Replace init file name */
  298.         rcflag = 1;        /* Flag that this has been done */
  299.         continue;
  300.         } else if (x == 'd') {    /* Do this early as possible! */
  301.         debopn("debug.log",0);
  302.         continue;
  303.         } else if (x == 'z') {    /* = SET BACKGROUND OFF */
  304.         bgset = 0;
  305.         continue;
  306.         } else if (x == 'S') {
  307.         stayflg = 1;
  308.         continue;
  309.         }
  310.     }
  311.     }
  312. #endif /* NOCMDL */
  313. }
  314.  
  315. static int tr_int;            /* Flag if TRANSMIT interrupted */
  316.  
  317. #ifndef MAC
  318. SIGTYP
  319. trtrap(foo) int foo; {            /* TRANSMIT interrupt trap */
  320. #ifdef __EMX__
  321.     signal(SIGINT, SIG_ACK);
  322. #endif
  323.     tr_int = 1;                /* (Need arg for ANSI C) */
  324.     SIGRETURN;
  325. }
  326. #endif /* MAC */
  327. /*  G E T T C S  --  Get Transfer (Intermediate) Character Set  */
  328.  
  329. /*
  330.   Given two file character sets, this routine picks out the appropriate
  331.   "transfer" character set to use for translating between them.
  332.   The transfer character set number is returned.
  333.  
  334.   Translation between two file character sets is done, for example,
  335.   by the CONNECT, TRANSMIT, and TRANSLATE commands.
  336.  
  337.   Translation between Kanji character sets is not yet supported.
  338. */
  339. int
  340. gettcs(cs1,cs2) int cs1, cs2; {
  341. #ifdef NOCSETS                /* No character-set support */
  342.     return(0);                /* so no translation */
  343. #else
  344.     int tcs = TC_TRANSP;
  345. #ifdef KANJI
  346. /* Kanji not supported yet */
  347.     if (fcsinfo[cs1].alphabet == AL_JAPAN ||
  348.     fcsinfo[cs2].alphabet == AL_JAPAN )
  349.       tcs = TC_TRANSP;
  350.     else
  351. #endif /* KANJI */
  352. #ifdef CYRILLIC
  353. /*
  354.   I can't remember why we don't test both sets here, but I think there
  355.   must have been a reason...
  356. */
  357.       if (fcsinfo[cs2].alphabet == AL_CYRIL)
  358.     tcs = TC_CYRILL;
  359.       else
  360. #endif /* CYRILLIC */
  361. #ifdef LATIN2
  362.     if (cs1 == FC_2LATIN || cs1 == FC_2LATIN ||
  363.         cs1 == FC_CP852  || cs1 == FC_CP852 )
  364.       tcs = TC_2LATIN;
  365.     else
  366. #endif /* LATIN2 */
  367. #ifdef HEBREW
  368.       if (fcsinfo[cs1].alphabet == AL_HEBREW ||
  369.           fcsinfo[cs2].alphabet == AL_HEBREW )
  370.         tcs = TC_HEBREW;
  371.       else
  372. #endif /* HEBREW */
  373.         tcs = TC_1LATIN;
  374.     return(tcs);
  375. #endif /* NOCSETS */
  376. }
  377.  
  378. #ifdef COMMENT
  379. /*
  380.   It seemed that this was needed for OS/2, in which \v(cmdfile) and other
  381.   file-oriented variables or functions can return filenames containing
  382.   backslashes, which are subsequently interpreted as quotes rather than
  383.   directory separators (e.g. see commented section for VN_CMDF below).
  384.   But the problem can't be cured at this level.  Example:
  385.  
  386.     type \v(cmdfile)
  387.  
  388.   Without doubling, the filename is parsed correctly, but then when passed
  389.   to UNIX 'cat' through the shell, the backslash is removed, and then cat
  390.   can't open the file.  With doubling, the filename is not parsed correctly
  391.   and the TYPE command fails immediately with a "file not found" error.
  392. */
  393. /*
  394.   Utility routine to double all backslashes in a string.
  395.   s1 is pointer to source string, s2 is pointer to destination string,
  396.   n is length of destination string, both NUL-terminated.
  397.   Returns 0 if OK, -1 if not OK (destination string too short).
  398. */
  399. int
  400. dblbs(s1,s2,n) char *s1, *s2; int n; {
  401.     int i = 0;
  402.     while (*s1) {
  403.     if (*s1 == '\\') {
  404.         if (++i > n) return(-1);
  405.         *s2++ = '\\';
  406.     }
  407.     if (++i > n) return(-1);
  408.     *s2++ = *s1++;
  409.     }
  410.     *s2 = NUL;
  411.     return(0);
  412. }
  413. #endif /* COMMENT */
  414.  
  415. #ifndef NOXMIT
  416. /*  T R A N S M I T  --  Raw upload  */
  417.  
  418. /*  Obey current line, duplex, parity, flow, text/binary settings. */
  419. /*  Returns 0 upon apparent success, 1 on obvious failure.  */
  420.  
  421. /***
  422.  Things to add:
  423.  . Make both text and binary mode obey set file bytesize.
  424.  . Maybe allow user to specify terminators other than CR?
  425.  . Maybe allow user to specify prompts other than single characters?
  426. ***/
  427.  
  428. /*  T R A N S M I T  --  Raw upload  */
  429.  
  430. /*  s is the filename, t is the turnaround (prompt) character  */
  431.  
  432. /*
  433.   Maximum number of characters to buffer.
  434.   Must be less than LINBUFSIZ
  435. */
  436. #define XMBUFS 120
  437.  
  438. int
  439. #ifdef CK_ANSIC
  440. transmit(char * s, char t)
  441. #else
  442. transmit(s,t) char *s; char t;
  443. #endif /* CK_ANSIC */
  444. /* transmit */ {
  445. #ifdef MAC
  446.     extern char sstate;
  447.     int count = 100;
  448. #else
  449.     SIGTYP (* oldsig)();        /* For saving old interrupt trap. */
  450. #endif /* MAC */
  451.     long zz;
  452.     int z = 1;                /* Return code. 0=fail, 1=succeed. */
  453.     int x, c, i;            /* Workers... */
  454.     int myflow;
  455.     CHAR csave;
  456.     char *p;
  457.  
  458. #ifndef NOCSETS
  459.     int tcs = TC_TRANSP;        /* Intermediate (xfer) char set */
  460.     int langsv = L_USASCII;        /* Save current language */
  461.  
  462.     _PROTOTYP ( CHAR (*sxo), (CHAR) ) = NULL; /* Translation functions */
  463.     _PROTOTYP ( CHAR (*rxo), (CHAR) ) = NULL;
  464.     _PROTOTYP ( CHAR (*sxi), (CHAR) ) = NULL;
  465.     _PROTOTYP ( CHAR (*rxi), (CHAR) ) = NULL;
  466. #endif /* NOCSETS */
  467.  
  468.     if (zopeni(ZIFILE,s) == 0) {    /* Open the file to be transmitted */
  469.     printf("?Can't open file %s\n",s);
  470.     return(0);
  471.     }
  472.     x = -1;                /* Open the communication line */
  473.     if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) {    /* (no harm if already open) */
  474.     printf("Can't open device %s\n",ttname);
  475.     return(0);
  476.     }
  477.     zz = x ? speed : -1L;
  478.     if (binary) {            /* Binary file transmission */
  479.     myflow = (flow == FLO_XONX) ? FLO_NONE : flow;
  480.     if (ttvt(zz,myflow) < 0) {    /* So no Xon/Xoff! */
  481.         printf("Can't condition line\n");
  482.         return(0);
  483.     }
  484.     } else {
  485.     if (ttpkt(zz,flow,parity) < 0) { /* Put the line in "packet mode" */
  486.         printf("Can't condition line\n"); /* so Xon/Xoff will work, etc. */
  487.         return(0);
  488.     }
  489.     }
  490.  
  491. #ifndef NOCSETS
  492.     tcs = gettcs(tcsr,tcsl);        /* Get intermediate set. */
  493.  
  494. /* Set up character set translations */
  495.     if (binary == 0) {
  496.  
  497.     if (tcsr == tcsl || binary) {    /* Remote and local sets the same? */
  498.         sxo = rxo = NULL;        /* Or file type is not text? */
  499.         sxi = rxi = NULL;
  500.     } else {            /* Otherwise, set up */
  501.         sxo = xls[tcs][tcsl];    /* translation function */
  502.         rxo = xlr[tcs][tcsr];    /* pointers for output functions */
  503.         sxi = xls[tcs][tcsr];    /* and for input functions. */
  504.         rxi = xlr[tcs][tcsl];
  505.     }
  506. /*
  507.   This is to prevent use of zmstuff() and zdstuff() by translation functions.
  508.   They only work with disk i/o, not with communication i/o.  Luckily Russian
  509.   translation functions don't do any stuffing...
  510. */
  511.     langsv = language;
  512.     language = L_USASCII;
  513.     }
  514. #endif /* NOCSETS */
  515.  
  516.     i = 0;                /* Beginning of buffer. */
  517. #ifndef MAC
  518. #ifndef AMIGA
  519.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  520. #endif /* AMIGA */
  521. #endif /* MAC */
  522.     tr_int = 0;                /* Have not been interrupted (yet). */
  523.     z = 1;                /* Return code presumed good. */
  524. #ifdef VMS
  525.     conres();
  526. #endif /* VMS */
  527.  
  528.     c = 0;                /* Initial condition */
  529.     while (c > -1) {            /* Loop for all characters in file */
  530. #ifdef MAC
  531.     /*
  532.      * It is expensive to run the miniparser so don't do it for
  533.      * every character.
  534.      */
  535.     if (--count < 0) {
  536.         count = 100;
  537.         miniparser(1);
  538.         if (sstate == 'a') {
  539.         sstate = '\0';
  540.         z = 0;
  541.         break;
  542.         }
  543.     }
  544. #else /* Not MAC */
  545.     if (tr_int) {            /* Interrupted? */
  546.         printf("^C...\n");        /* Print message */
  547.         z = 0;
  548.         break;
  549.     }
  550. #endif /* MAC */
  551.     c = zminchar();            /* Get a file character */
  552.     debug(F101,"transmit char","",c);
  553.     if (c == -1)            /* Test for end-of-file */
  554.       break;
  555.     c &= fmask;            /* Apply SET FILE BYTESIZE mask */
  556.  
  557.     if (binary) {            /* If binary file, */
  558.         if (ttoc(dopar((char) c)) < 0) { /* else just send the char */
  559.         printf("?Can't transmit character\n");
  560.         z = 0;
  561.         break;
  562.         }
  563.         if (xmitw) msleep(xmitw);    /* Pause if requested */
  564.         if (xmitx) {        /* SET TRANSMIT ECHO ON? */
  565.         if (duplex) {        /* Yes, for half duplex */
  566.             conoc((char)(c & cmdmsk)); /* echo locally. */
  567.         } else {        /* For full duplex, */
  568.             int i, n;        /* display whatever is there. */
  569.             n = ttchk();    /* How many chars are waiting? */
  570.             for (i = 0; i < n; i++) { /* Read and echo that many. */
  571.             x = ttinc(1);    /* Timed read just in case. */
  572.             if (x > -1) {    /* If no timeout */
  573.                 if (parity) x &= 0x7f;
  574.                 conoc((char)(x & cmdmsk)); /* display the char, */
  575.             } else break;    /* otherwise stop reading. */
  576.             }
  577.         }
  578.         } else ttflui();        /* Not echoing, just flush input. */
  579.  
  580.     } else {            /* Text mode, line at a time. */
  581.  
  582.         if (c == '\n') {        /* Got a line */
  583.         if (i == 0) {        /* Blank line? */
  584.             if (xmitf)        /* Yes, insert fill if asked. */
  585.               line[i++] = dopar((char) xmitf);
  586.         }
  587.         if (i == 0 || line[i-1] != dopar(CR))
  588.           line[i++] = dopar(CR); /* Terminate it with CR */
  589.         if (
  590.             xmitl
  591. #ifdef TNCODE
  592.             || (network && ttnproto == NP_TELNET && tn_nlm)
  593. #endif /* TNCODE */
  594.             )
  595.           line[i++] = dopar(LF); /* Include LF if asked */
  596.  
  597.         } else if (c != -1) {    /* Not a newline, regular character */
  598.         csave = c;        /* Remember untranslated version */
  599. #ifndef NOCSETS
  600.         /* Translate character sets */
  601.         if (sxo) c = (*sxo)((CHAR)c); /* From local to intermediate */
  602.         if (rxo) c = (*rxo)((CHAR)c); /* From intermediate to remote */
  603. #endif /* NOCSETS */
  604.  
  605.         if (xmits && parity && (c & 0200)) { /* If shifting */
  606.             line[i++] = dopar(SO);          /* needs to be done, */
  607.             line[i++] = dopar((char)c);        /* do it here, */
  608.             line[i++] = dopar(SI);          /* crudely. */
  609.         } else {
  610.             line[i++] = dopar((char)c); /* else, just char itself */
  611.         }
  612.         }
  613.  
  614. /* Send characters if buffer full, or at end of line, or at end of file */
  615.  
  616.         if (i >= XMBUFS || c == '\n' || c == -1) {
  617.         p = line;
  618.         line[i] = '\0';
  619.         debug(F111,"transmit buf",p,i);
  620.         if (ttol((CHAR *)p,i) < 0) { /* try to send it. */
  621.             printf("Can't send buffer\n");
  622.             z = 0;
  623.             break;
  624.         }
  625.         i = 0;            /* Reset buffer pointer. */
  626.  
  627. /* Worry about echoing here. "xmitx" is SET TRANSMIT ECHO flag. */
  628.  
  629.         if (duplex && xmitx) {    /* If local echo, echo it */
  630.             if (parity || cmdmsk == 0x7f) { /* Strip off high bits */
  631.             char *s = p;            /* if necessary */
  632.             while (*s) {
  633.                 *s &= 0x7f;
  634.                 s++;
  635.             }
  636.             conoll(p);
  637.             }
  638.         }
  639.         if (xmitw)        /* Give receiver time to digest. */
  640.           msleep(xmitw);
  641.         if (t != 0 && c == '\n') { /* Want a turnaround character */
  642.             x = 0;           /* Wait for it */
  643.             while (x != t) {
  644.             if ((x = ttinc(1)) < 0) break;
  645.             if (xmitx && !duplex) {    /* Echo any echoes */
  646.                 if (parity) x &= 0x7f;
  647. #ifndef NOCSETS
  648.                 if (sxi) x = (*sxi)((CHAR)x); /* But translate */
  649.                 if (rxi) x = (*rxi)((CHAR)x); /* them first... */
  650. #endif /* NOCSETS */
  651.                 conoc((char) x);
  652.             }
  653.             }
  654.         } else if (xmitx && !duplex) { /* Otherwise, */
  655.             while (ttchk() > 0) {      /* echo for as long as */
  656.             if ((x = ttinc(0)) < 0) break; /* anything is there. */
  657.             if (parity) x &= 0x7f;
  658. #ifndef NOCSETS
  659.             if (sxi) x = (*sxi)((CHAR)x); /* Translate first */
  660.             if (rxi) x = (*rxi)((CHAR)x);
  661. #endif /* NOCSETS */
  662.             conoc((char)x);
  663.             }
  664.         } else ttflui();    /* Otherwise just flush input buffer */
  665.         }                /* End of buffer-dumping block */
  666.     }                /* End of text mode */
  667.     }                    /* End of character-reading loop */
  668.  
  669.     if (*xmitbuf) {            /* Anything to send at EOF? */
  670.     p = xmitbuf;            /* Yes, point to string. */
  671.     while (*p)            /* Send it. */
  672.       ttoc(dopar(*p++));        /* Don't worry about echo here. */
  673.     }
  674.  
  675. #ifndef AMIGA
  676. #ifndef MAC
  677.     signal(SIGINT,oldsig);        /* Put old signal action back. */
  678. #endif /* MAC */
  679. #endif /* AMIGA */
  680. #ifdef VMS
  681.     concb(escape);            /* Put terminal back, */
  682. #endif /* VMS */
  683.     zclose(ZIFILE);            /* Close file, */
  684. #ifndef NOCSETS
  685.     language = langsv;            /* restore language, */
  686. #endif /* NOCSETS */
  687.     return(z);                /* and return successfully. */
  688. }
  689. #endif /* NOXMIT */
  690.  
  691. #ifdef MAC
  692. /*
  693.   This code is not used any more, except on the Macintosh.  Instead we call
  694.   system to do the typing.  Revive this code if your system can't be called
  695.   to do this.
  696. */
  697.  
  698. /*  D O T Y P E  --  Type a file  */
  699.  
  700. int
  701. dotype(s) char *s; {
  702.  
  703. #ifdef MAC
  704.     extern char sstate;
  705.     int count = 100;
  706. #else
  707.     SIGTYP (* oldsig)();        /* For saving old interrupt trap. */
  708. #endif /* MAC */
  709.     int z;                /* Return code. */
  710.     int c;                /* Worker. */
  711.  
  712.     if (zopeni(ZIFILE,s) == 0) {    /* Open the file to be typed */
  713.     printf("?Can't open %s\n",s);
  714.     return(0);
  715.     }
  716. #ifndef AMIGA
  717. #ifndef MAC
  718.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  719. #endif /* MAC */
  720. #endif /* AMIGA */
  721.  
  722.     tr_int = 0;                /* Have not been interrupted (yet). */
  723.     z = 1;                /* Return code presumed good. */
  724.  
  725. #ifdef VMS
  726.     conoc(CR);                /* On VMS, display blank line first */
  727.     conoc(LF);
  728.     conres();                /* So Ctrl-C/Y will work */
  729. #endif /* VMS */
  730.     while ((c = zminchar()) != -1) {    /* Loop for all characters in file */
  731. #ifdef MAC
  732.     /*
  733.      * It is expensive to run the miniparser so don't do it for
  734.      * every character.
  735.      */
  736.     if (--count < 0) {
  737.         count = 100;
  738.         miniparser(1);
  739.         if (sstate == 'a') {
  740.         sstate = '\0';
  741.         z = 0;
  742.         break;
  743.         }
  744.     }
  745.     putchar(c);
  746. #else /* Not MAC */
  747.     if (tr_int) {            /* Interrupted? */
  748.         printf("^C...\n");        /* Print message */
  749.         z = 0;
  750.         break;
  751.     }
  752.     conoc(c);            /* Echo character on screen */
  753. #endif /* MAC */
  754.     }
  755. #ifndef AMIGA
  756. #ifndef MAC
  757.     signal(SIGINT,oldsig);        /* put old signal action back. */
  758. #endif /* MAC */
  759. #endif /* AMIGA */
  760.  
  761.     tr_int = 0;
  762. #ifdef VMS
  763.     concb(escape);            /* Get back in command-parsing mode, */
  764. #endif /* VMS */
  765.     zclose(ZIFILE);            /* close file, */
  766.     return(z);                /* and return successfully. */
  767. }
  768. #endif /* MAC */
  769.  
  770. #ifndef NOCSETS
  771.  
  772. _PROTOTYP( CHAR (*sxx), (CHAR) );       /* Local translation function */
  773. _PROTOTYP( CHAR (*rxx), (CHAR) );       /* Local translation function */
  774. _PROTOTYP( CHAR zl1as, (CHAR) );    /* Latin-1 to ascii */
  775. _PROTOTYP( CHAR xl1as, (CHAR) );    /* ditto */
  776.  
  777. /*  X L A T E  --  Translate a local file from one character set to another */
  778.  
  779. /*
  780.   Translates input file (fin) from character set csin to character set csout
  781.   and puts the result in the output file (fout).  The two character sets are
  782.   file character sets from fcstab.
  783. */
  784.  
  785. int
  786. xlate(fin, fout, csin, csout) char *fin, *fout; int csin, csout; {
  787.  
  788. #ifndef MAC
  789.     SIGTYP (* oldsig)();        /* For saving old interrupt trap. */
  790. #endif /* MAC */
  791.     int filecode;            /* Code for output file */
  792.  
  793.     int z = 1;                /* Return code. */
  794.     int c, tcs;                /* Workers */
  795.  
  796.     if (zopeni(ZIFILE,fin) == 0) {    /* Open the file to be translated */
  797.     printf("?Can't open input file %s\n",fin);
  798.     return(0);
  799.     }
  800. #ifdef MAC
  801. /*
  802.   If user specified no output file, it goes to the screen.  For the Mac,
  803.   this must be done a special way (result goes to a new window); the Mac
  804.   doesn't have a "controlling terminal" device name.
  805. */
  806.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZOFILE;
  807. #else
  808. #ifdef VMS
  809.     filecode = !strcmp(fout,CTTNAM) ? ZCTERM : ZMFILE;
  810. #else
  811.     filecode = ZOFILE;
  812. #endif /* VMS */
  813. #endif /* MAC */
  814.  
  815.     if (zopeno(filecode,fout,NULL,NULL) == 0) { /* And the output file */
  816.     printf("?Can't open output file %s\n",fout);
  817.     return(0);
  818.     }
  819. #ifndef AMIGA
  820. #ifndef MAC
  821.     oldsig = signal(SIGINT, trtrap);    /* Save current interrupt trap. */
  822. #endif /* MAC */
  823. #endif /* AMIGA */
  824.  
  825.     tr_int = 0;                /* Have not been interrupted (yet). */
  826.     z = 1;                /* Return code presumed good. */
  827.  
  828.     tcs = gettcs(csin,csout);        /* Get intermediate set. */
  829.  
  830.     printf("%s (%s) => %s (%s)\n",    /* Say what we're doing. */
  831.        fin, fcsinfo[csin].name,
  832.        fout,fcsinfo[csout].name
  833.     );
  834.     printf("via %s", tcsinfo[tcs].name);
  835.     if (language)
  836.       printf(", language: %s\n",langs[language].description);
  837.     printf("\n\n");
  838.  
  839.     if (csin == csout) {        /* Input and output sets the same? */
  840.     sxx = rxx = NULL;        /* If so, no translation. */
  841.     } else {                /* Otherwise, set up */
  842.     sxx = xls[tcs][csin];        /* translation function */
  843.     rxx = xlr[tcs][csout];        /* pointers. */
  844.     if (rxx == zl1as) rxx = xl1as;
  845.     }
  846.     while ((c = zminchar()) != -1) {    /* Loop for all characters in file */
  847.     if (tr_int) {            /* Interrupted? */
  848.         printf("^C...\n");        /* Print message */
  849.         z = 0;
  850.         break;
  851.     }
  852.     if (sxx) c = (*sxx)((CHAR)c);    /* From fcs1 to tcs */
  853.     if (rxx) c = (*rxx)((CHAR)c);    /* from tcs to fcs2 */
  854.  
  855.     if (zchout(filecode,(char)c) < 0) { /* Output the xlated character */
  856.         printf("File output error\n");
  857.         z = 0;
  858.         break;
  859.     }
  860.     }
  861. #ifndef AMIGA
  862. #ifndef MAC
  863.     signal(SIGINT,oldsig);        /* put old signal action back. */
  864. #endif /* MAC */
  865. #endif /* AMIGA */
  866.  
  867.     tr_int = 0;
  868.     zclose(ZIFILE);            /* close files, */
  869.     zclose(filecode);
  870.     return(z);                /* and return successfully. */
  871. }
  872. #endif /* NOCSETS */
  873.  
  874. /*  D O L O G  --  Do the log command  */
  875.  
  876. int
  877. dolog(x) int x; {
  878.     int y, disp; char *s;
  879.  
  880.     switch (x) {
  881.  
  882. #ifdef DEBUG
  883.     case LOGD:
  884.         y = cmofi("Name of debugging log file","debug.log",&s,xxstring);
  885.         break;
  886. #endif /* DEBUG */
  887.  
  888.     case LOGP:
  889.         y = cmofi("Name of packet log file","packet.log",&s,xxstring);
  890.         break;
  891.  
  892.     case LOGS:
  893.         y = cmofi("Name of session log file","session.log",&s,xxstring);
  894.         break;
  895.  
  896. #ifdef TLOG
  897.     case LOGT:
  898.         y = cmofi("Name of transaction log file","transact.log",&s,
  899.               xxstring);
  900.         break;
  901. #endif /* TLOG */
  902.  
  903.     default:
  904.         printf("\n?Unknown log designator - %d\n",x);
  905.         return(-2);
  906.     }
  907.     if (y < 0) return(y);
  908.  
  909.     strcpy(line,s);
  910.     s = line;
  911.     if ((y = cmkey(disptb,2,"Disposition","new",xxstring)) < 0)
  912.       return(y);
  913.     disp = y;
  914.     if ((y = cmcfm()) < 0) return(y);
  915.  
  916.     switch (x) {
  917.  
  918. #ifdef DEBUG
  919.     case LOGD:
  920.         return(deblog = debopn(s,disp));
  921. #endif /* DEBUG */
  922.  
  923.     case LOGP:
  924.         return(pktlog = pktopn(s,disp));
  925.  
  926.     case LOGS:
  927.         return(seslog = sesopn(s,disp));
  928.  
  929. #ifdef TLOG
  930.     case LOGT:
  931.         return(tralog = traopn(s,disp));
  932. #endif /* TLOG */
  933.  
  934.     default:
  935.         return(-2);
  936.     }
  937. }
  938.  
  939. int
  940. pktopn(s,disp) char *s; int disp; {
  941.     extern char pktfil[];
  942.     static struct filinfo xx;
  943.     int y;
  944.  
  945.     zclose(ZPFILE);
  946.     if(s[0] == '\0') return(0);
  947.     if (disp) {
  948.     xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  949.     xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = '\0';
  950.     xx.lblopts = 0;
  951.     y = zopeno(ZPFILE,s,NULL,&xx);
  952.     } else y = zopeno(ZPFILE,s,NULL,NULL);
  953.     if (y > 0)
  954.       strcpy(pktfil,s);
  955.     else
  956.       *pktfil = '\0';
  957.     return(y);
  958. }
  959.  
  960. int
  961. traopn(s,disp) char *s; int disp; {
  962. #ifdef TLOG
  963.     extern char trafil[];
  964.     static struct filinfo xx;
  965.     int y;
  966.  
  967.     zclose(ZTFILE);
  968.     if(s[0] == '\0') return(0);
  969.     if (disp) {
  970.     xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  971.     xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = '\0';
  972.     xx.lblopts = 0;
  973.     y = zopeno(ZTFILE,s,NULL,&xx);
  974.     } else y = zopeno(ZTFILE,s,NULL,NULL);
  975.     if (y > 0) {
  976.     strcpy(trafil,s);
  977.     tlog(F110,"Transaction Log:",versio,0L);
  978. #ifndef MAC
  979.     tlog(F100,ckxsys,"",0L);
  980. #endif /* MAC */
  981.     ztime(&s);
  982.     tlog(F100,s,"",0L);
  983.     } else *trafil = '\0';
  984.     return(y);
  985. #else
  986.     return(0);
  987. #endif
  988. }
  989.  
  990. int
  991. sesopn(s,disp) char * s; int disp; {
  992.     extern char sesfil[];
  993.     static struct filinfo xx;
  994.     int y;
  995.  
  996.     zclose(ZSFILE);
  997.     if(s[0] == '\0') return(0);
  998.     if (disp) {
  999.     xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  1000.     xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = '\0';
  1001.     xx.lblopts = 0;
  1002.     y = zopeno(ZSFILE,s,NULL,&xx);
  1003.     } else y = zopeno(ZSFILE,s,NULL,NULL);
  1004.     if (y > 0)
  1005.       strcpy(sesfil,s);
  1006.     else
  1007.       *sesfil = '\0';
  1008.     return(y);
  1009. }
  1010.  
  1011. int
  1012. debopn(s,disp) char *s; int disp; {
  1013. #ifdef DEBUG
  1014.     char *tp;
  1015.     static struct filinfo xx;
  1016.  
  1017.     zclose(ZDFILE);
  1018.  
  1019.     if (disp) {
  1020.     xx.bs = 0; xx.cs = 0; xx.rl = 0; xx.org = 0; xx.cc = 0;
  1021.     xx.typ = 0; xx.dsp = XYFZ_A; xx.os_specific = '\0';
  1022.     xx.lblopts = 0;
  1023.     deblog = zopeno(ZDFILE,s,NULL,&xx);
  1024.     } else deblog = zopeno(ZDFILE,s,NULL,NULL);
  1025.     if (deblog > 0) {
  1026.     strcpy(debfil,s);
  1027.     debug(F110,"Debug Log ",versio,0);
  1028. #ifndef MAC
  1029.     debug(F100,ckxsys,"",0);
  1030. #endif /* MAC */
  1031.     ztime(&tp);
  1032.     debug(F100,tp,"",0);
  1033.     } else *debfil = '\0';
  1034.     return(deblog);
  1035. #else
  1036.     return(0);
  1037. #endif
  1038. }
  1039.  
  1040. #ifndef NOSHOW
  1041.  
  1042. /*  S H O P A R  --  Show Parameters  */
  1043.  
  1044. #ifdef SUNX25
  1045. VOID
  1046. shox25() {
  1047.     if (nettype == NET_SX25) {
  1048.     printf("SunLink X.25 V%d.%d",x25ver / 10,x25ver % 10);
  1049.     if (ttnproto == NP_X3) printf(", PAD X.3, X.28, X.29 protocol,");
  1050.     printf("\n Reverse charge call %s",
  1051.            revcall ? "selected" : "not selected");
  1052.     printf (", Closed user group ");
  1053.     if (closgr > -1)
  1054.       printf ("%d",closgr);
  1055.     else
  1056.       printf ("not selected");
  1057.     printf (",");
  1058.     printf("\n Call user data %s.\n", cudata ? udata : "not selected");
  1059.     }
  1060. }
  1061. #endif /* SUNX25 */
  1062.  
  1063. VOID
  1064. shoparc() {
  1065.     int i; char *s;
  1066.     long zz;
  1067.  
  1068.     puts("Communications Parameters:");
  1069.  
  1070.     if (network) {
  1071.     printf(" Host: %s",ttname);
  1072.     } else {
  1073.     printf(" Line: %s, speed: ",ttname);
  1074.     if ((zz = ttgspd()) < 0) {
  1075.         printf("unknown");
  1076.         } else {
  1077.         if (speed == 8880) printf("75/1200"); else printf("%ld",zz);
  1078.     }
  1079.     }
  1080.     printf(", mode: ");
  1081.     if (local) printf("local"); else printf("remote");
  1082.     if (network == 0) {
  1083. #ifndef NODIAL
  1084.     for (i = 0; i < nmdm; i++) {
  1085.         if (mdmtab[i].kwval == mdmtyp) {
  1086.         printf(", modem: %s",mdmtab[i].kwd);
  1087.         break;
  1088.         }
  1089.     }
  1090. #endif /* NODIAL */
  1091.     } else {
  1092.     if (nettype == NET_TCPA) printf(", TCP/IP");
  1093.     if (nettype == NET_TCPB) printf(", TCP/IP");
  1094.         if (nettype == NET_DEC) {
  1095.           if ( ttnproto == NP_LAT ) printf(", DECnet LAT");
  1096.           else if ( ttnproto == NP_CTERM ) printf(", DECnet CTERM");
  1097.           else printf(", DECnet");
  1098.         }
  1099.         if (nettype == NET_PIPE) printf(", Named Pipe");
  1100. #ifdef SUNX25
  1101.     shox25();
  1102. #endif /* SUNX25 */
  1103.     if (ttnproto == NP_TELNET) printf(", telnet protocol");
  1104.     }
  1105.     if (local) {
  1106.     i = parity ? 7 : 8;
  1107.     if (i == 8) i = (cmask == 0177) ? 7 : 8;
  1108.     printf("\n Terminal bits: %d, p",i);
  1109.     } else printf("\n P");
  1110.     printf("arity: %s",parnam((char)parity));
  1111.     printf(", duplex: ");
  1112.     if (duplex) printf("half, "); else printf("full, ");
  1113.     printf("flow: ");
  1114.     if (flow == FLO_KEEP) printf("keep");
  1115.         else if (flow == FLO_XONX) printf("xon/xoff");
  1116.     else if (flow == FLO_NONE) printf("none");
  1117.     else if (flow == FLO_DTRT) printf("dtr/cts");
  1118.     else if (flow == FLO_RTSC) printf("rts/cts");
  1119.         else if (flow == FLO_DTRC) printf("dtr/cd");
  1120.     else printf("%d",flow);
  1121.     printf(", handshake: ");
  1122.     if (turn) printf("%d\n",turnch); else printf("none\n");
  1123.     if (local && !network) {        /* Lockfile & carrier stuff */
  1124.     if (carrier == CAR_OFF) s = "off";
  1125.     else if (carrier == CAR_ON) s = "on";
  1126.     else if (carrier == CAR_AUT) s = "auto";
  1127.     else s = "unknown";
  1128.     printf(" Carrier: %s", s);
  1129.     if (carrier == CAR_ON) {
  1130.         if (cdtimo) printf(", timeout: %d sec", cdtimo);
  1131.         else printf(", timeout: none");
  1132.     }
  1133. #ifdef UNIX
  1134.     if (haslock && *flfnam) {    /* Lockfiles only apply to UNIX... */
  1135.         printf(", lockfile: %s",flfnam);
  1136.     }
  1137. #endif /* UNIX */
  1138.     printf("\n Escape character: %d (^%c)\n",escape,ctl(escape));
  1139.     }
  1140. }
  1141.  
  1142. #ifdef TNCODE
  1143. static VOID
  1144. shotel() {
  1145.     printf("SET TELNET parameters:\n echo: %s\n newline-mode: %s\n",
  1146.        tn_duplex ? "local" : "remote", tn_nlm ? "on" : "off");
  1147.     printf(" terminal-type: ");
  1148.     if (tn_term) printf("%s\n",tn_term);
  1149.     else {
  1150.     char *p;
  1151.     p = getenv("TERM");
  1152.     if (p)
  1153.       printf("none (%s will be used)\n",p);
  1154.     else printf("none\n");
  1155.     }
  1156. }
  1157. #endif /* TNCODE */
  1158.  
  1159. VOID
  1160. shonet() {
  1161. #ifndef NETCONN
  1162.     printf("\nNo networks are supported in this version of C-Kermit\n");
  1163. #else
  1164.     printf("\nSupported networks:\n");
  1165.  
  1166. #ifdef VMS
  1167.  
  1168. #ifdef MULTINET
  1169.     printf(" TGV MultiNet TCP/IP");
  1170. #else
  1171. #ifdef WINTCP
  1172.     printf(" WOLLONGONG WIN/TCP");
  1173. #else
  1174. #ifdef DEC_TCPIP
  1175.     printf(" DEC TCP/IP Services for (Open)VMS");
  1176. #else
  1177.     printf(" None");
  1178. #endif /* DEC_TCPIP */
  1179. #endif /* WINTCP */
  1180. #endif /* MULTINET */
  1181. #ifdef TNCODE
  1182.     printf(", TELNET protocol\n\n");
  1183.     shotel();
  1184. #endif /* TNCODE */
  1185.     printf("\n");
  1186.  
  1187. #else /* Not VMS */
  1188.  
  1189. #ifdef SUNX25
  1190.     printf(" SunLink X.25\n");
  1191. #endif /* SUNX25 */
  1192. #ifdef DECNET
  1193. #ifdef OS2
  1194.     printf(" DECnet, LAT protocol\n");
  1195. #else
  1196.     printf(" DECnet\n");
  1197. #endif /* OS2 */
  1198. #endif /* DECNET */
  1199. #ifdef NPIPE
  1200.     printf(" LAN Manager Named Pipe\n");
  1201. #endif /* DECNET */
  1202. #ifdef TCPSOCKET
  1203.     printf(" TCP/IP");
  1204. #ifdef TNCODE
  1205.     printf(", TELNET protocol\n\n");
  1206.     shotel();
  1207. #endif /* TNCODE */
  1208. #endif /* TCPSOCKET */
  1209.     printf("\n");
  1210.  
  1211. #endif /* VMS */
  1212.  
  1213.     printf("Current network type:\n");
  1214.     if (nettype == NET_TCPA || nettype == NET_TCPB)
  1215.       printf(" TCP/IP\n");
  1216. #ifdef SUNX25
  1217.     else if (nettype == NET_SX25) printf(" X.25\n");
  1218. #endif /* SUNX25 */
  1219. #ifdef DECNET
  1220.     else if (nettype == NET_DEC) printf(" DECnet\n");
  1221. #endif /* DECNET */
  1222.  
  1223.     printf("\nActive SET HOST connection:\n");
  1224.     if (network) {
  1225.     printf(" %s",ttname);
  1226.     if (*ipaddr) printf(" [%s]",ipaddr);
  1227.     printf("\n Via: ");
  1228.     if (nettype == NET_TCPA || nettype == NET_TCPB) printf("TCP/IP\n");
  1229.     else if (nettype == NET_SX25) printf("SunLink X.25\n");
  1230.     else if (nettype == NET_DEC) {
  1231.           if ( ttnproto == NP_LAT ) printf("DECnet LAT\n");
  1232.           else if ( ttnproto == NP_CTERM ) printf("DECnet CTERM\n");
  1233.           else printf("DECnet\n");
  1234.         }
  1235.     else if (nettype == NET_PIPE) printf("LAN Manager Named Pipe\n");
  1236. #ifdef SUNX25
  1237.     if (nettype == NET_SX25) shox25();
  1238. #endif /* SUNX25 */
  1239. #ifdef TNCODE
  1240.     if (ttnproto == NP_TELNET) {
  1241.         printf(" TELNET protocol\n");
  1242.         printf(" Echoing is currently %s\n",duplex ? "local" : "remote");
  1243.     }
  1244. #endif /* TNCODE */
  1245.     } else printf(" None\n");
  1246.     printf("\n");
  1247. #endif /* NETCONN */
  1248. }
  1249.  
  1250. #ifndef NODIAL
  1251.  
  1252. VOID
  1253. shodial() {
  1254.     if (mdmtyp >= 0 || local != 0) doshodial();
  1255. }
  1256.  
  1257. static VOID
  1258. shods(s) char *s; {            /* Show a dial-related string */
  1259.     char c;
  1260.     if (s == NULL || !(*s)) {        /* Empty? */
  1261.     printf("(none)\n");
  1262.     } else {                /* Not empty. */
  1263.     while (c = *s++)             /* Can contain controls */
  1264.       if (c > 31 && c < 127) { putchar(c); } /* so display them */
  1265.       else printf("\\{%d}",c);         /* in backslash notation */
  1266.     printf("\n");
  1267.     }
  1268. }
  1269.  
  1270. int
  1271. doshodial() {
  1272.     printf(" Dial directory: %s\n",dialdir ? dialdir : "(none)");
  1273.     printf(" Dial hangup: %s, dial modem-hangup: %s\n",
  1274.        dialhng ? "on" : "off", dialmhu ? "on" : "off") ;
  1275.     printf(" Dial kermit-spoof: %s",dialksp ? "on" : "off");
  1276.     printf(", dial display: %s\n",dialdpy ? "on" : "off");
  1277.     printf(" Dial speed-matching: %s",mdmspd ? "on" : "off");
  1278.     printf(", dial mnp-enable: %s\n",dialmnp ? "on" : "off");
  1279.     printf(" Dial init-string: ");
  1280.     shods(getdws(mdmtyp));        /* Ask dial module for it */
  1281.     printf(" Dial dial-command: ");
  1282.     shods(getdcs(mdmtyp));        /* Ask dial module for it */
  1283.     printf(" Dial prefix: ");
  1284.     shods(dialnpr);
  1285.     printf(" Dial timeout: ");
  1286.     if (dialtmo > 0)
  1287.       printf("%d sec", dialtmo);
  1288.     else
  1289.       printf("0 (auto)");
  1290.     printf(", Redial number: %s\n",dialnum ? dialnum : "(none)");
  1291.     return(0);
  1292. }
  1293. #endif /* NODIAL */
  1294.  
  1295. #ifdef SUNX25
  1296. VOID
  1297. shopad() {
  1298.     int i;
  1299.     printf("\nX.3 PAD Parameters:\n");
  1300.     for (i = 0; i < npadx3; i++)
  1301.       printf(" [%d] %s %d\n",padx3tab[i].kwval,padx3tab[i].kwd,
  1302.          padparms[padx3tab[i].kwval]);
  1303. }
  1304. #endif /* SUNX25 */
  1305.  
  1306. /*  Show File Parameters */
  1307.  
  1308. VOID
  1309. shoparf() {
  1310.     char *s; int i;
  1311.     printf("\nFile parameters:       ");
  1312. #ifdef COMMENT
  1313.     printf("Blocksize:     %5d      ",fblksiz);
  1314. #endif /* COMMENT */
  1315.     printf(" Attributes:       ");
  1316.     if (atcapr) printf("on"); else printf("off");
  1317. #ifdef VMS
  1318.     printf("  Record-Length: %5d",frecl);
  1319. #endif /* VMS */
  1320.     printf("\n Names:   ");
  1321.     printf("%-12s",(fncnv) ? "converted" : "literal");
  1322. #ifdef DEBUG
  1323. #ifndef MAC
  1324.     printf("  Debugging Log:    ");
  1325.     if (deblog) printf("%s",debfil); else printf("none");
  1326. #endif /* MAC */
  1327. #endif /* DEBUG */
  1328.  
  1329.     printf("\n Type:    ");
  1330.     switch (binary) {
  1331.       case XYFT_T: s = "text";    break;
  1332. #ifdef VMS
  1333.       case XYFT_B: s = "binary fixed"; break;
  1334.       case XYFT_I: s = "image";        break;
  1335.       case XYFT_L: s = "labeled";      break;
  1336.       case XYFT_U: s = "binary undef"; break;
  1337. #else
  1338.       case XYFT_B: s = "binary"; break;
  1339. #endif /* VMS */
  1340.       default: s = "?"; break;
  1341.     }
  1342.     printf("%-12s",s);
  1343. #ifdef COMMENT
  1344.     printf(" Organization:  ");
  1345.     switch (forg) {
  1346.       case XYFO_I: printf("%-10s","indexed"); break;
  1347.       case XYFO_R: printf("%-10s","relative"); break;
  1348.       case XYFO_S: printf("%-10s","sequential"); break;
  1349.     }
  1350. #endif /* COMMENT */
  1351. #ifndef MAC
  1352.     printf("  Packet Log:       ");
  1353.     if (pktlog) printf(pktfil); else printf("none");
  1354. #endif /* MAC */
  1355. #ifdef UNIX
  1356.     printf("  Longest filename: %d",maxnam);
  1357. #endif /* UNIX */
  1358.     printf("\n Collide: ");
  1359.     for (i = 0; i < ncolx; i++)
  1360.       if (colxtab[i].kwval == fncact) break;
  1361.     printf("%-12s", (i == ncolx) ? "unknown" : colxtab[i].kwd);
  1362.  
  1363. #ifdef COMMENT
  1364.     printf(" Format:        ");
  1365.     switch (frecfm) {
  1366.       case XYFF_F:  printf("%-10s","fixed"); break;
  1367.       case XYFF_VB: printf("%-10s","rcw"); break;
  1368.       case XYFF_S:  printf("%-10s","stream"); break;
  1369.       case XYFF_U:  printf("%-10s","undefined"); break;
  1370.       case XYFF_V:  printf("%-10s","variable"); break;
  1371.     }
  1372. #endif /* COMMENT */
  1373. #ifndef MAC
  1374.     printf("  Session Log:      ");
  1375.     if (seslog) printf(sesfil); else printf("none");
  1376. #endif /* MAC */
  1377. #ifdef UNIX
  1378.     printf("  Longest pathname: %d",maxpath);
  1379. #endif /* UNIX */
  1380.     printf("\n Display: ");
  1381.     switch (fdispla) {
  1382.       case XYFD_N: printf("%-12s","none"); break;
  1383.       case XYFD_R: printf("%-12s","serial"); break;
  1384.       case XYFD_C: printf("%-12s","fullscreen"); break;
  1385.       case XYFD_S: printf("%-12s","crt"); break;
  1386.     }
  1387. #ifdef COMMENT
  1388.     printf("Carriage-Control: ");
  1389.     switch (fcctrl) {
  1390.       case XYFP_F: printf("%-10s","fortran"); break;
  1391.       case XYFP_N: printf("%-10s","newline"); break;
  1392.       case XYFP_P: printf("%-10s","machine"); break;
  1393.       case XYFP_X: printf("%-10s","none"); break;
  1394.     }
  1395. #endif /* COMMENT */
  1396. #ifdef TLOG
  1397. #ifndef MAC
  1398.     printf("  Transaction Log:  ");
  1399.     if (tralog) printf(trafil); else printf("none");
  1400. #endif /* MAC */
  1401. #endif /* TLOG */
  1402. #ifndef NOCSETS
  1403.     if (binary == XYFT_T) {
  1404.     shocharset();
  1405.     } else
  1406. #endif /* NOCSETS */
  1407.       printf("\n");
  1408.     printf("\nFile Byte Size: %d",(fmask == 0177) ? 7 : 8);
  1409.     printf(", Incomplete Files: ");
  1410.     if (keep) printf("keep"); else printf("discard");
  1411. #ifdef KERMRC
  1412.     printf(", Init file: %s",kermrc);
  1413. #endif /* KERMRC */
  1414.     printf("\n");
  1415. }
  1416.  
  1417. VOID
  1418. shoparp() {
  1419.     printf("\nProtocol Parameters:   Send    Receive");
  1420.     if (timef)
  1421.       printf("\n Timeout (used=%2d):%7d*%8d ", timint, rtimo, pkttim);
  1422.     else
  1423.       printf("\n Timeout (used=%2d):%7d%9d ",  timint, rtimo, pkttim);
  1424. #ifndef NOSERVER
  1425.     printf("       Server Timeout:%4d\n",srvtim);
  1426. #endif /* NOSERVER */
  1427.     printf(  " Padding:      %11d%9d", npad,   mypadn);
  1428.     if (bctr == 4)
  1429.       printf("        Block Check: blank-free-2\n");
  1430.     else
  1431.       printf("        Block Check: %6d\n",bctr);
  1432.     printf(  " Pad Character:%11d%9d", padch,  mypadc);
  1433.     printf("        Delay:       %6d\n",delay);
  1434.     printf(  " Packet Start: %11d%9d", mystch, stchr);
  1435.     printf("        Max Retries: %6d\n",maxtry);
  1436.     printf(  " Packet End:   %11d%9d", seol,   eol);
  1437.     if (ebqflg)
  1438.       printf("        8th-Bit Prefix: '%c'",ebq);
  1439. #ifdef COMMENT
  1440. /*
  1441.   This is confusing.
  1442. */
  1443.     printf(  "\n Packet Length:%11d", spsizf ? spsizr : spsiz);
  1444.     printf( spsizf ? "*" : " " ); printf("%8d",  urpsiz);
  1445.     printf( (urpsiz > 94) ? " (94)" : "     ");
  1446. #else
  1447.     printf(  "\n Packet Length:%11d ", spmax);
  1448.     printf("%8d     ",  urpsiz);
  1449. #endif /* COMMENT */
  1450.     if (rptflg)
  1451.       printf("   Repeat Prefix:  '%c'",rptq);
  1452.     printf(  "\n Maximum Length: %9d%9d", maxsps, maxrps);
  1453.     printf("        Window Size:%7d set, %d used\n",wslotr,wmax);
  1454.     printf(    " Buffer Size:  %11d%9d", bigsbsiz, bigrbsiz);
  1455.     printf("        Locking-Shift:    ");
  1456.     if (lscapu == 2) {
  1457.     printf("forced\n");
  1458.     } else {
  1459.     printf("%s", (lscapr ? "enabled" : "disabled"));
  1460.     if (lscapr) printf(",%s%s", (lscapu ? " " : " not "), "used");
  1461.     printf("\n");
  1462.     }
  1463. }
  1464.  
  1465. #ifndef NOCSETS
  1466. VOID
  1467. shoparl() {
  1468. #ifdef COMMENT
  1469.     int i;
  1470. /* Misleading... */
  1471.     printf("\nAvailable Languages:\n");
  1472.     for (i = 0; i < MAXLANG; i++) {
  1473.     printf(" %s\n",langs[i].description);
  1474.     }
  1475. #else
  1476.     printf("\nLanguage-specific translation rules: %s\n",
  1477.        language == L_USASCII ? "none" : langs[language].description);
  1478.     shocharset();
  1479.     printf("\n\n");
  1480. #endif /* COMMENT */
  1481. }
  1482.  
  1483. VOID
  1484. shocharset() {
  1485.     int x;
  1486.     printf("\n File Character-Set: %s (",fcsinfo[fcharset].name);
  1487.     if ((x = fcsinfo[fcharset].size) == 128) printf("7-bit)");
  1488.     else if (x == 256) printf("8-bit)");
  1489.     else printf("(multibyte)");
  1490.     printf("\n Transfer Character-Set");
  1491. #ifdef COMMENT
  1492.     if (tslevel == TS_L2)
  1493.       printf(": (international)");
  1494.     else
  1495. #endif /* COMMENT */
  1496.     if (tcharset == TC_TRANSP)
  1497.       printf(": Transparent");
  1498.     else
  1499.       printf(": %s",tcsinfo[tcharset].name);
  1500. }
  1501. #endif /* NOCSETS */
  1502.  
  1503. VOID
  1504. shopar() {
  1505. #ifndef MAC
  1506.     printf("\n%s,%s\n",versio,ckxsys);
  1507. #endif /* MAC */
  1508.     shoparc();
  1509.     shoparp();
  1510.     shoparf();
  1511. }
  1512. #endif /* NOSHOW */
  1513.  
  1514. /*  D O S T A T  --  Display file transfer statistics.  */
  1515.  
  1516. int
  1517. dostat() {
  1518.     printf("\nMost recent transaction --\n");
  1519.     printf("\n files: %ld\n",filcnt);
  1520.     printf(" characters last file   : %ld\n",ffc);
  1521.     printf(" total file characters  : %ld\n",tfc);
  1522.     printf(" communication line in  : %ld\n",tlci);
  1523.     printf(" communication line out : %ld\n",tlco);
  1524.     printf(" packets sent           : %d\n", spackets);
  1525.     printf(" packets received       : %d\n", rpackets);
  1526.     printf(" damaged packets rec'd  : %d\n", crunched);
  1527.     printf(" timeouts               : %d\n", timeouts);
  1528.     printf(" retransmissions        : %d\n", retrans);
  1529.     if (filcnt > 0) {
  1530.     printf(" parity                 : %s",parnam((char)parity));
  1531.     if (autopar) printf(" (detected automatically)");
  1532.     printf("\n 8th bit prefixing      : ");
  1533.     if (ebqflg) printf("yes [%c]\n",ebq); else printf("no\n");
  1534.     printf(" locking shifts         : %s\n", lscapu ? "yes" : "no");
  1535.     printf(" window slots used      : %d of %d\n", wmax, wslotr);
  1536.     printf(" packet length          : %d (send), %d (receive)\n",
  1537.            spmax, urpsiz);
  1538.     printf(" compression            : ");
  1539.     if (rptflg)
  1540.       printf("yes [%c] (%ld)\n",(char) rptq,rptn);
  1541.     else
  1542.       printf("no\n");
  1543.     if (bctu == 4)
  1544.       printf(" block check type used  : blank-free-2\n");
  1545.     else
  1546.       printf(" block check type used  : %d\n",bctu);
  1547.     printf(" elapsed time           : %d sec\n",tsecs);
  1548.     if (speed <= 0L) speed = ttgspd();
  1549.     if (speed > 0L) {
  1550.         if (speed == 8880)
  1551.           printf(" transmission rate      : 75/1200 bps\n");
  1552.         else
  1553.           printf(" transmission rate      : %ld bps\n",speed);
  1554.     }
  1555.     if (tsecs > 0) {
  1556.         long ecps;            /* Effective data rate, cps */
  1557.         int eff;            /* Percent efficiency */
  1558.         ecps = tfc / (long) tsecs;
  1559.         printf(" effective data rate    : %ld cps\n", ecps);
  1560.         if (speed > 99L && speed != 8880L && network == 0) {
  1561.         eff = (((ecps * 100L) / (speed / 100L)) + 5L) / 10L;
  1562.         printf(" efficiency (percent)   : %d\n", eff);
  1563.         }
  1564.     }
  1565.     }
  1566.     return(1);
  1567. }
  1568.  
  1569. /*  D O C O N E C T  --  Do the connect command  */
  1570.  
  1571. /*  Note, we don't call this directly from dial, because we need to give */
  1572. /*  the user a chance to change parameters (e.g. parity) after the */
  1573. /*  connection is made. */
  1574.  
  1575. int
  1576. doconect() {
  1577.     int x;
  1578.     conres();                /* Put console back to normal */
  1579.     x = conect();            /* Connect */
  1580.     concb((char)escape);        /* Put console into cbreak mode, */
  1581.     return(x);                /* for more command parsing. */
  1582. }
  1583.  
  1584. #ifndef NOSPL
  1585. /* The INPUT command */
  1586.  
  1587. #ifdef NETCONN
  1588. extern int tn_init;
  1589. #ifndef IAC
  1590. #define IAC 255
  1591. #endif /* IAC */
  1592. #endif /* NETCONN */
  1593.  
  1594. int
  1595. doinput(timo,s) int timo; char *s; {
  1596.     int x, y, i, t, icn, anychar;
  1597.     int lastchar = 0;
  1598.     char *xp, *xq = (char *)0;
  1599.     CHAR c;
  1600.  
  1601.     if (local) {            /* Put line in "ttvt" mode */
  1602.     y = ttvt(speed,flow);        /* if not already. */
  1603.     if (y < 0) {
  1604.         printf("?Can't condition line for INPUT\n");
  1605.         return(0);            /* Watch out for failure. */
  1606.     }
  1607.     }
  1608.     if (!s) s = "";
  1609.     y = (int)strlen(s);            /* If search string is empty */
  1610.     anychar = (y < 1);            /* any input character will do. */
  1611.     debug(F111,"doinput",s,y);
  1612.     if (timo <= 0) timo = 1;        /* Give at least 1 second timeout */
  1613.  
  1614.     x = 0;                /* Return code, assume failure */
  1615.     i = 0;                /* String pattern match position */
  1616.  
  1617.     if (!inpcas[cmdlvl]) {        /* INPUT CASE = IGNORE?  */
  1618.     xp = malloc(y+2);        /* Make a separate copy of the */
  1619.     if (!xp) {            /* input string for editing. */
  1620.         printf("?malloc error 5\n");
  1621.         return(x);
  1622.     } else xq = xp;            /* Save pointer to beginning */
  1623.  
  1624.     while (*s) {            /* Convert to lowercase */
  1625.         *xp = *s;
  1626.         if (isupper(*xp)) *xp = tolower(*xp);
  1627.         xp++; s++;
  1628.     }
  1629.     *xp = NUL;            /* Terminate the search string. */
  1630.     s = xq;                /* Point back to beginning. */
  1631.     }
  1632.     inpbps = inpbp;            /* Save current pointer. */
  1633.     rtimer();                /* Reset timer. */
  1634.     t = 0;                /* Time is 0. */
  1635.     incount = 0;            /* Character counter */
  1636.     while (1) {                /* Character-getting loop */
  1637.     if (local) {            /* One case for local */
  1638.         y = ttinc(1);        /* Get character from comm line. */
  1639.         debug(F101,"input ttinc(1) returns","",y);
  1640.         if (icn = conchk()) {    /* Interrupted from keyboard? */
  1641.         debug(F101,"input interrupted from keyboard","",icn);
  1642.         while (icn--) coninc(0); /* Yes, absorb what was typed. */
  1643.         break;            /* And fail. */
  1644.         }
  1645.     } else {            /* Another for remote */
  1646.         y = coninc(1);
  1647.         debug(F101,"input coninc(1) returns","",y);
  1648.     }
  1649.     if (y > -1) {            /* A character arrived */
  1650. #ifdef TNCODE
  1651. /* Check for telnet protocol negotiation */
  1652.         if (network && (ttnproto == NP_TELNET) && ((y & 0xff) == IAC)) {
  1653.         switch (tn_doop((CHAR)(y & 0xff),duplex,ttinc)) {
  1654.           case 2: duplex = 0; continue;
  1655.           case 1: duplex = 1;
  1656.           default: continue;
  1657.         }
  1658.         }
  1659. #endif /* TNCODE */
  1660.  
  1661.         /* Real input character to be checked */
  1662.  
  1663.         c = cmask & (CHAR) y;    /* Mask off parity */
  1664.  
  1665.         inchar[0] = c;        /* Remember character for \v(inchar) */
  1666.         lastchar = gtimer();    /* Remember when it came. */
  1667.  
  1668.         if (c == '\0') {        /* NUL, we can't use it */
  1669.         if (anychar) {        /* Any character will do? */
  1670.             x = 1;        /* Yes, done. */
  1671.             incount = 1;    /* This must be the first and only. */
  1672.             break;
  1673.         } else continue;    /* Otherwise continue INPUTting */
  1674.         }
  1675.  
  1676.         *inpbp++ = c;        /* Store char in circular buffer */
  1677.         incount++;            /* Count it for \v(incount) */
  1678.  
  1679.         if (inpbp >= inpbuf + INPBUFSIZ) { /* Time to wrap around? */
  1680.         inpbp = inpbuf;        /* Yes. */
  1681.         *(inpbp+INPBUFSIZ) = NUL; /* Make sure it's null-terminated. */
  1682.         }
  1683. #ifdef MAC
  1684.         {
  1685.         extern char *ttermw;    /* fake pointer cast */
  1686.         if (inecho) {
  1687.             outchar(ttermw, c);    /* echo to terminal window */
  1688.             /* this might be too much overhead to do here ? */
  1689.             updatecommand(ttermw);
  1690.         }
  1691.         }
  1692. #else /* Not MAC */
  1693.         if (inecho) conoc(c);    /* Echo and log the input character */
  1694. #endif /* MAC */
  1695.         if (seslog) {
  1696. #ifdef UNIX
  1697.         if (sessft != 0 || c != '\r')
  1698. #endif /* UNIX */
  1699.           if (zchout(ZSFILE,c) < 0) seslog = 0;
  1700.         }
  1701.         if (anychar) {        /* Any character will do? */
  1702.         x = 1;
  1703.         break;
  1704.         }
  1705.         if (!inpcas[cmdlvl]) {    /* Ignore alphabetic case? */
  1706.         if (isupper(c)) c = tolower(c); /* Yes */
  1707.         }
  1708.         debug(F000,"doinput char","",c);
  1709.         debug(F000,"compare char","",(CHAR)s[i]);
  1710.         if (c == (CHAR) s[i]) {    /* Check for match */
  1711.         i++;            /* Got one, go to next character */
  1712.         } else {            /* Don't have a match */
  1713.            int j, size;
  1714.            for (j = i; i-- > 0; ) { /* [jrs] search backwards */
  1715.                if (c == (CHAR) s[i]) {
  1716.                size = j - i;
  1717.                if (strncmp(s,&s[j-i],i-size)== 0)
  1718.               break;
  1719.                }
  1720.            }
  1721.            i++;            /* [jrs] count last char matched    */
  1722.            }                /* [jrs] or return to zero from -1  */
  1723.         if ((CHAR) s[i] == (CHAR) '\0') { /* Matched all the way to end? */
  1724.         x = 1;            /* Yes, */
  1725.         break;            /* done. */
  1726.         }
  1727.     }
  1728.     if ((t = gtimer()) > timo)    /* Did not match, timer exceeded? */
  1729.       break;
  1730.     else if (insilence > 0 && (t - lastchar) > insilence)
  1731.       break;
  1732.     }                    /* Still have time left, continue. */
  1733.     if (!inpcas[cmdlvl]) if (xq) free(xq); /* Done, free dynamic memory. */
  1734.     return(x);                /* Return the return code. */
  1735. }
  1736. #endif /* NOSPL */
  1737.  
  1738. #ifndef NOSPL
  1739. /* REINPUT Command */
  1740.  
  1741. /* Note, the timeout parameter is required, but ignored. */
  1742. /* Syntax is compatible with MS-DOS Kermit except timeout can't be omitted. */
  1743. /* This function only looks at the characters already received */
  1744. /* and does not read any new characters from the communication line. */
  1745.  
  1746. int
  1747. doreinp(timo,s) int timo; char *s; {
  1748.     int x, y, i;
  1749.     char *xx, *xp, *xq = (char *)0;
  1750.     CHAR c;
  1751.  
  1752.     y = (int)strlen(s);
  1753.     debug(F111,"doreinput",s,y);
  1754.  
  1755.     x = 0;                /* Return code, assume failure */
  1756.     i = 0;                /* String pattern match position */
  1757.  
  1758.     if (!inpcas[cmdlvl]) {        /* INPUT CASE = IGNORE?  */
  1759.     xp = malloc(y+2);        /* Make a separate copy of the */
  1760.     if (!xp) {            /* search string. */
  1761.         printf("?malloc error 6\n");
  1762.         return(x);
  1763.     } else xq = xp;            /* Keep pointer to beginning. */
  1764.     while (*s) {            /* Yes, convert to lowercase */
  1765.         *xp = *s;
  1766.         if (isupper(*xp)) *xp = tolower(*xp);
  1767.         xp++; s++;
  1768.     }
  1769.     *xp = NUL;            /* Terminate it! */
  1770.     s = xq;                /* Move search pointer to it. */
  1771.     }
  1772.     xx = inpbp;                /* Current INPUT buffer pointer */
  1773.     do {
  1774.     c = *xx++;            /* Get next character */
  1775.     if (xx >= inpbuf + INPBUFSIZ) xx = inpbuf; /* Wrap around */
  1776.     if (!inpcas[cmdlvl]) {        /* Ignore alphabetic case? */
  1777.         if (isupper(c)) c = tolower(c); /* Yes */
  1778.     }
  1779.     debug(F000,"doreinp char","",c);
  1780.     debug(F000,"compare char","",(CHAR) s[i]);
  1781.     if (c == s[i]) {        /* Check for match */
  1782.         i++;            /* Got one, go to next character */
  1783.     } else {            /* Don't have a match */
  1784.            int j, size;
  1785.            for (j = i; i-- > 0; ) { /* [jrs] search backwards for it  */
  1786.            if (c == s[i]) {
  1787.             size = j - i;
  1788.             if (strncmp(s,&s[j-i],i-size)== 0)
  1789.               break;
  1790.         }
  1791.            }
  1792.            i++;            /* [jrs] count last char matched */
  1793.        }                /* [jrs] or return to zero from -1 */
  1794.     if (s[i] == '\0') {        /* Matched all the way to end? */
  1795.         x = 1;            /* Yes, */
  1796.         break;            /* done. */
  1797.     }
  1798.     } while (xx != inpbp);        /* Until back where we started. */
  1799.  
  1800.     if (!inpcas[cmdlvl]) if (xq) free(xq); /* Free this if it was malloc'd. */
  1801.     return(x);                /* Return search result. */
  1802. }
  1803. #ifndef NOSPL
  1804.  
  1805. #endif /* NOSPL */
  1806. /*  X X S T R I N G  --  Interpret strings containing backslash escapes  */
  1807.  
  1808. /*
  1809.  Copies result to new string.
  1810.   strips enclosing braces or doublequotes.
  1811.   interprets backslash escapes.
  1812.   returns 0 on success, nonzero on failure.
  1813.   tries to be compatible with MS-DOS Kermit.
  1814.  
  1815.  Syntax of input string:
  1816.   string = chars | "chars" | {chars}
  1817.   chars = (c*e*)*
  1818.   where c = any printable character, ascii 32-126
  1819.   and e = a backslash escape
  1820.   and * means 0 or more repetitions of preceding quantity
  1821.   backslash escape = \operand
  1822.   operand = {number} | number | fname(operand) | v(name) | $(name) | m(name)
  1823.   number = [r]n[n[n]]], i.e. an optional radix code followed by 1-3 digits
  1824.   radix code is oO (octal), hHxX (hex), dD or none (decimal).
  1825. */
  1826.  
  1827. #ifndef NOFRILLS
  1828. int
  1829. yystring(s,s2) char *s; char **s2; {    /* Reverse a string */
  1830.     int x;
  1831.     static char *new;
  1832.     new = *s2;
  1833.     if (!s || !new) return(-1);        /* Watch out for null pointers. */
  1834.     if ((x = (int)strlen(s)) == 0) {    /* Recursion done. */
  1835.     *new = '\0';
  1836.     return(0);
  1837.     }
  1838.     x--;                /* Otherwise, call self */
  1839.     *new++ = s[x];            /* to reverse rest of string. */
  1840.     s[x] = 0;
  1841.     return(yystring(s,&new));
  1842. }
  1843. #endif /* NOFRILLS */
  1844.  
  1845. #define FNVALL 1000
  1846. char fnval[FNVALL+2];            /* Return value */
  1847.  
  1848. char *                    /* Evaluate builtin function */
  1849. fneval(fn,argp,argn) char *fn, *argp[]; int argn; {
  1850.     int i, j, k, len1, len2, len3, n, x, y;
  1851.     char *bp[FNARGS];            /* Pointers to malloc'd strings */
  1852.     char *p, *s;
  1853.  
  1854.     if (!fn) fn = "";            /* Paranoia */
  1855.     debug(F111,"fneval",fn,argn);
  1856.     debug(F110,"fneval",argp[0],0);
  1857.     y = lookup(fnctab,fn,nfuncs,&x);
  1858.     if (y < 0)                /* bad function name */
  1859.       return("");            /* so value is null */
  1860.  
  1861. #ifdef DEBUG
  1862.     if (deblog) {
  1863.     int j;
  1864.     for (j = 0; j < argn; j++)
  1865.       debug(F111,"fneval function arg",argp[j],j);
  1866.     }
  1867. #endif /* DEBUG */
  1868.  
  1869.     if (y == FN_LIT)            /* literal(arg1) */
  1870.       return(argp[0] ? argp[0] : "");    /* return a pointer to arg itself */
  1871.  
  1872.     if (y == FN_CON) {            /* Contents of variable, unexpanded. */
  1873.     char c;
  1874.     if (!(p = argp[0]) || !*p) return("");
  1875.     if (*p == CMDQ) p++;
  1876.     if ((c = *p) == '%') {        /* Scalar variable. */
  1877.         c = *++p;            /* Get ID character. */
  1878.         p = "";            /* Assume definition is empty */
  1879.         if (!c) return(p);        /* Double paranoia */
  1880.         if (c >= '0' && c <= '9') { /* Digit for macro arg */
  1881.         c -= '0';        /* convert character to integer */
  1882.         if (maclvl < 0)        /* Digit variables are global */
  1883.           p = g_var[c];        /* if no macro is active */
  1884.         else            /* otherwise */
  1885.           p = m_arg[maclvl][c]; /* they're on the stack */
  1886.         } else {
  1887.         if (isupper(c)) c -= ('a'-'A');
  1888.         p = g_var[c];        /* Letter for global variable */
  1889.         }
  1890.         return(p ? p : "");
  1891.     }
  1892.     if (c == '&') {            /* Array reference. */
  1893.         int vbi, d;
  1894.         if (arraynam(p,&vbi,&d) < 0) /* Get name and subscript */
  1895.           return("");
  1896.         if (chkarray(vbi,d) > 0) {    /* Array is declared? */
  1897.         vbi -= 'a';        /* Convert name to index */
  1898.         if (a_dim[vbi] >= d) {    /* If subscript in range */
  1899.             char **ap;
  1900.             ap = a_ptr[vbi];    /* get data pointer */
  1901.             if (ap) {        /* and if there is one */
  1902.             return(ap[d]);    /* return what it points to */
  1903.             }
  1904.         }
  1905.         }
  1906.         return(p ? p : "");        /* Otherwise its enexpanded value. */
  1907.     }
  1908.     }
  1909.  
  1910.     for (i = 0; i < argn; i++) {    /* Not literal, expand the args */
  1911.     n = 1024;            /* allow 1K per expanded arg, yow! */
  1912.     bp[i] = s = malloc(n);        /* get the new space */
  1913.     if (bp[i] == NULL) {        /* handle failure to get space */
  1914.         for (k = 0; k < i; k++) if (bp[k]) free(bp[k]);
  1915.         debug(F101,"fneval malloc failure, arg","",i);
  1916.         return("");
  1917.     }
  1918.     p = argp[i] ? argp[i] : "";    /* Point to this argument */
  1919.  
  1920. /*
  1921.   Trim leading and trailing spaces from the original argument, before
  1922.   evaluation.  This code new to edit 184.
  1923. */
  1924.     if (y != FN_REP || i != 0) {    /* Don't trim 1st REPEAT argument */
  1925.         int j;            /* All others... */
  1926.         while (*p == SP || *p == HT) /* Point past leading whitespace */
  1927.           p++;
  1928.         j = (int) strlen(p) - 1;    /* Trim trailing whitespace */
  1929.         while (j > 0 && (*(p + j) == SP || *(p + j) == HT))
  1930.           *(p + j--) = NUL;
  1931.     }
  1932.  
  1933. /* Now evaluate the argument */
  1934.  
  1935.     if (xxstring(p,&s,&n) < 0) {    /* Expand arg into new space */
  1936.         debug(F101,"fneval xxstring fails, arg","",i);
  1937.         for (k = 0; k <= i; k++)    /* Free up previous space on error */
  1938.           if (bp[k]) free(bp[k]);
  1939.         return("");            /* and return null string. */
  1940.     }
  1941.     debug(F111,"fneval arg",bp[i],i);
  1942.     }
  1943.  
  1944. #ifdef DEBUG
  1945.     if (deblog) {
  1946.     int j;
  1947.     for (j = 0; j < argn; j++) {
  1948.         debug(F111,"fneval arg post eval",argp[j],j);
  1949.         debug(F111,"fneval evaluated arg",bp[j],j);
  1950.     }
  1951.     }
  1952. #endif /* DEBUG */
  1953.  
  1954.     switch (y) {            /* Do function on expanded args */
  1955.  
  1956.       case FN_DEF:
  1957.     k = mlook(mactab,bp[0],nmac);    /* def(arg1) - Return a macro def */
  1958.     p = (k > -1) ? mactab[k].mval : "";
  1959.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  1960.     return(p ? p : "");
  1961.  
  1962.       case FN_EVA:            /* eval(arg1) */
  1963.     p = evala(bp[0]);
  1964.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  1965.     return(p ? p : "");
  1966.  
  1967.       case FN_EXE:            /* execute(arg1) */
  1968.     j = (int)strlen(s = bp[0]);    /* Length of macro invocation */
  1969.     p = "";                /* Initialize return value to null */
  1970.     if (j) {            /* If there is a macro to execute */
  1971.         while (*s == SP) s++,j--;    /* strip leading spaces */
  1972.         p = s;            /* remember beginning of macro name */
  1973.         for (i = 0; i < j; i++) {    /* find end of macro name */
  1974.         if (*s == SP) break;
  1975.         s++;
  1976.         }
  1977.         if (*s == SP) {        /* if there was a space after */
  1978.         *s++ = NUL;        /* terminate the macro name */
  1979.         while (*s == SP) s++;    /* skip past any extra spaces */
  1980.         } else s = "";        /* maybe there are no arguments */
  1981.         if (p && *p)
  1982.           k = mlook(mactab,p,nmac);    /* Look up the macro name */
  1983.         else k = -1;
  1984.  
  1985.         p = "";            /* Initialize return value */
  1986.         if (k >= 0) {        /* If macro found in table */
  1987.         if ((j = dodo(k,s)) > 0) { /* Go set it up (like DO cmd) */
  1988.             if (cmpush() > -1) { /* Push command parser state */
  1989.             extern int ifc;
  1990.             int ifcsav = ifc; /* Push IF condition on stack */
  1991.             k = parser(1);    /* Call parser to execute the macro */
  1992.             cmpop();    /* Pop command parser */
  1993.             ifc = ifcsav;    /* Restore IF condition */
  1994.             if (k == 0) {    /* No errors, ignore action cmds. */
  1995.                 p = mrval[maclvl+1]; /* If OK, set return value. */
  1996.                 if (p == NULL) p = "";
  1997.             }
  1998.             } else {        /* Can't push any more */
  1999.             debug(F100,"fexec pushed too deep","",0);
  2000.                         printf("\n?\\fexec() too deeply nested\n");
  2001.             while (cmpop() > -1) ;
  2002.             p = "";
  2003.             }
  2004.         }
  2005.         }
  2006.     }
  2007.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2008.     return(p ? p : "");
  2009.  
  2010.       case FN_FC:            /* File count. */
  2011.     p = fnval;
  2012.     *p = NUL;
  2013.     if (argn > 0) {
  2014.         k = zxpand(bp[0]);
  2015.         sprintf(fnval,"%d",k);
  2016.         for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2017.     }
  2018.     return(p);
  2019.  
  2020.       case FN_FIL:            /* Next file in list. */
  2021.     p = fnval;            /* (no args) */
  2022.     *p = NUL;
  2023.     znext(p);
  2024.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2025.     return(p ? p : "");
  2026.  
  2027.       case FN_IND:            /* index(arg1,arg2) */
  2028.     if (argn > 1) {            /* Only works if we have 2 args */
  2029.         int start;
  2030.         len1 = (int)strlen(bp[0]);    /* length of string to look for */
  2031.         len2 = (int)strlen(s = bp[1]); /* length of string to look in */
  2032.         if (len1 < 0) return("");    /* paranoia */
  2033.         if (len2 < 0) return("");
  2034.         j = len2 - len1;        /* length difference */
  2035.         start = 0;            /* starting position */
  2036.         if (argn > 2) {
  2037.         if (chknum(bp[2])) {
  2038.             start = atoi(bp[2]) - 1;
  2039.             if (start < 0) start = 0;
  2040.         }
  2041.         }
  2042.         if (j < 0 || start > j) {    /* search string is longer */
  2043.         p = "0";
  2044.         } else {
  2045.         if (!inpcas[cmdlvl]) {    /* input case ignore? */
  2046.             lower(bp[0]);
  2047.             lower(bp[1]);
  2048.         }
  2049.         s = bp[1] + start;    /* Point to beginning of target */
  2050.         p = "0";
  2051.         for (i = 0; i <= (j - start); i++) { /* Now compare */
  2052.             if (!strncmp(bp[0],s++,len1)) {
  2053.             sprintf(fnval,"%d",i+1+start);
  2054.             p = fnval;
  2055.             break;
  2056.             }
  2057.         }
  2058.         }
  2059.     } else p = "0";
  2060.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2061.     return(p);
  2062.  
  2063.       case FN_RPL:            /* replace(s1,s2,s3) */
  2064.     p = fnval;
  2065.     if (argn < 2) {            /* Only works if we have 2 or 3 args */
  2066.         strcpy(p,bp[0]);
  2067.     } else  {            
  2068.         len1 = (int)strlen(bp[0]);    /* length of string to look in */
  2069.         len2 = (int)strlen(bp[1]);    /* length of string to look for */
  2070.         len3 = (argn < 3) ? 0 : (int)strlen(bp[2]); /* Len of replacemnt */
  2071.         j = len1 - len2 + 1;
  2072.         if (j < 1 || len1 == 0 || len2 == 0) { /* Args out of whack */
  2073.         strcpy(p,bp[0]);    /* so just return original string */
  2074.         } else {
  2075.         s = bp[0];        /* Point to beginning of string */
  2076.         while (j--) {        /* For each character */
  2077.             if (inpcas[cmdlvl] ?
  2078.             !strncmp(bp[1],s,len2) :
  2079.             !xxstrcmp(bp[1],s,len2) ) { /* To be replaced? */
  2080.             if (len3) {            /* Yes, */
  2081.                 strncpy(p,bp[2],len3);  /* replace it */
  2082.                 p += len3;
  2083.             }
  2084.             s += len2;                /* and skip past it. */
  2085.             } else {        /* No, */
  2086.             *p++ = *s++;    /* just copy this character */
  2087.             }
  2088.         }
  2089.         *p = NUL;
  2090.         }
  2091.     }
  2092.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2093.     return(p = fnval);
  2094.  
  2095.       case FN_CHR:            /* character(arg1) */
  2096.     if (chknum(bp[0])) {        /* Must be numeric */
  2097.         i = atoi(bp[0]);
  2098.         if (i >= 0 && i < 256) {    /* Must be an 8-bit value */
  2099.         p = fnval;
  2100.         *p++ = i;
  2101.         *p = NUL;
  2102.         p = fnval;
  2103.         } else p = "";        /* Otherwise return null */
  2104.     } else p = "";            /* Otherwise return null */
  2105.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2106.     return(p);
  2107.  
  2108.       case FN_COD:            /* code(char) */
  2109.     p = "";
  2110.     if ((int)strlen(bp[0]) > 0) {
  2111.         p = fnval;
  2112.         i = *bp[0];
  2113.         sprintf(p,"%d",(i & 0xff));
  2114.     }
  2115.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2116.     return(p);
  2117.  
  2118.       case FN_LEN:            /* length(arg1) */
  2119.     p = fnval;
  2120.     sprintf(p,"%d",(int)strlen(bp[0]));
  2121.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2122.     return(p);
  2123.  
  2124.       case FN_LOW:            /* lower(arg1) */
  2125.     s = bp[0];
  2126.     p = fnval;
  2127.  
  2128.     while (*s) {
  2129.         if (isupper(*s))
  2130.           *p = tolower(*s);
  2131.         else
  2132.           *p = *s;
  2133.         p++; s++;
  2134.     }
  2135.     *p = NUL;
  2136.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2137.     p = fnval;
  2138.     return(p);
  2139.  
  2140.       case FN_MAX:            /* max(arg1,arg2) */
  2141.       case FN_MIN:            /* min(arg1,arg2) */
  2142.       case FN_MOD:            /* mod(arg1,arg2) */
  2143.     if (chknum(bp[0]) && chknum(bp[1])) {
  2144.         i = atoi(bp[0]);
  2145.         j = atoi(bp[1]);
  2146.         switch (y) {
  2147.           case FN_MAX:
  2148.         if (j < i) j = i;
  2149.         break;
  2150.           case FN_MIN:
  2151.         if (j > i) j = i;
  2152.         break;
  2153.           case FN_MOD:
  2154.         j = i % j;
  2155.         break;
  2156.         }
  2157.         p = fnval;
  2158.         sprintf(p,"%d",j);
  2159.     } else p = "";
  2160.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2161.     return(p);
  2162.  
  2163.       case FN_SUB:            /* substr(arg1,arg2,arg3) */
  2164.       case FN_RIG:            /* right(arg1,arg2) */
  2165.     if (((argn > 1) && (int)strlen(bp[1]) && !rdigits(bp[1])) ||
  2166.         ((y == FN_SUB) &&
  2167.         ((argn > 2) && (int)strlen(bp[2]) && !rdigits(bp[2])))) {
  2168.         p = "";            /* if either, return null */
  2169.     } else {
  2170.         int lx;
  2171.         p = fnval;                     /* pointer to result */
  2172.         lx = strlen(bp[0]);             /* length of arg1 */
  2173.         if (y == FN_SUB) {             /* substring */
  2174.         k = (argn > 2) ? atoi(bp[2]) : 1023; /* length */
  2175.         j = (argn > 1) ? atoi(bp[1]) : 1; /* start pos for substr */
  2176.         } else {                 /* right */
  2177.         k = (argn > 1) ? atoi(bp[1]) : lx; /* length */
  2178.         j = lx - k + 1;             /* start pos for right */
  2179.         if (j < 1) j = 1;
  2180.         }
  2181.         if (k > 0 && j <= lx) {          /* if start pos in range */
  2182.         s = bp[0]+j-1;             /* point to source string */
  2183.         for (i = 0; (i < k) && (*p++ = *s++); i++) ;  /* copy */
  2184.         }
  2185.         *p = NUL;            /* terminate the result */
  2186.         p = fnval;            /* and point to it. */
  2187.     }
  2188.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]); /* Free temp mem */
  2189.     return(p);
  2190.  
  2191.       case FN_UPP:            /* upper(arg1) */
  2192.     s = bp[0];
  2193.     p = fnval;
  2194.     while (*s) {
  2195.         if (islower(*s))
  2196.           *p = toupper(*s);
  2197.         else
  2198.           *p = *s;
  2199.         p++; s++;
  2200.     }
  2201.     *p = NUL;
  2202.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2203.     p = fnval;
  2204.     return(p);
  2205.  
  2206.       case FN_REP:            /* Repeat */
  2207.     p = "";                /* Return value */
  2208.     if (chknum(bp[1])) {        /* Repeat count */
  2209.         n = atoi(bp[1]);
  2210.         if (n > 0) {        /* Make n copies */
  2211.         p = fnval;
  2212.         *p = '\0';
  2213.         k = (int)strlen(bp[0]);    /* Make sure string has some length */
  2214.         if (k > 0) {
  2215.             for (i = 0; i < n; i++) {
  2216.             s = bp[0];
  2217.             for (j = 0; j < k; j++) {
  2218.                 if ((p - fnval) >= FNVALL) { /* Protect against */
  2219.                 p = "";                 /* core dumps... */
  2220.                 break;
  2221.                 } else *p++ = *s++;
  2222.             }
  2223.             }
  2224.             *p = NUL;
  2225.         }
  2226.         }
  2227.     }
  2228.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2229.     p = fnval;
  2230.     return(p);
  2231.  
  2232. #ifndef NOFRILLS
  2233.       case FN_REV:
  2234.     p = fnval;
  2235.     yystring(bp[0],&p);
  2236.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2237.     return(p);
  2238. #endif /* NOFRILLS */
  2239.  
  2240.       case FN_RPA:            /* RPAD and LPAD */
  2241.       case FN_LPA:
  2242.     *fnval = NUL;            /* Return value */
  2243.     if (argn == 1) {        /* If a number wasn't given */
  2244.         p = fnval;            /* just return the original string */
  2245.         strncpy(p,bp[0],FNVALL);
  2246.     } else if (chknum(bp[1])) {    /* Repeat count */
  2247.         char pc;
  2248.         n = atoi(bp[1]);
  2249.         if (n >= 0) {        /* Pad it out */
  2250.         p = fnval;
  2251.         k = (int)strlen(bp[0]);    /* Length of string to be padded */
  2252.         pc = (argn < 3) ? SP : *bp[2]; /* Padding character */
  2253.         if (n > FNVALL) n = FNVALL-1; /* protect against overruns */
  2254.         if (k > FNVALL) k = FNVALL-1; /* and silly args. */
  2255.                 if (k > n) k = n;
  2256.         if (y == FN_RPA) {    /* RPAD */
  2257.             strncpy(p,bp[0],k);
  2258.             p += k;
  2259.             for (i = k; i < n; i++)
  2260.               *p++ = pc;
  2261.         } else {        /* LPAD */
  2262.             n -= k;
  2263.             for (i = 0; i < n; i++)
  2264.               *p++ = pc;
  2265.             strncpy(p,bp[0],k);
  2266.             p += k;
  2267.         }
  2268.         *p = NUL;
  2269.         }
  2270.     }
  2271.     for (k = 0; k < argn; k++) if (bp[k]) free(bp[k]);
  2272.     p = fnval;
  2273.     return(p);
  2274.  
  2275.       default:
  2276.     return("");
  2277.     }
  2278. }
  2279. #endif /* NOSPL */
  2280.  
  2281. #ifndef NOSPL
  2282.  
  2283. char *                    /* Evaluate builtin variable */
  2284. nvlook(s) char *s; {
  2285.     int x, y;
  2286.     long z;
  2287.     char *p;
  2288.  
  2289.     x = 30;
  2290.     p = vvbuf;
  2291.     if (xxstring(s,&p,&x) < 0) {
  2292.     y = -1;
  2293.     } else {
  2294.     s = vvbuf;
  2295.     if ((y = lookup(vartab,s,nvars,&x)) < 0) return(NULL);
  2296.     }
  2297.     switch (y) {
  2298.       case VN_ARGC:            /* ARGC */
  2299.     sprintf(vvbuf,"%d",macargc[maclvl]);
  2300.     return(vvbuf);
  2301.  
  2302.       case VN_ARGS:            /* ARGS */
  2303.     sprintf(vvbuf,"%d",xargs);
  2304.     return(vvbuf);
  2305.  
  2306.       case VN_COUN:            /* COUNT */
  2307.     sprintf(vvbuf,"%d",count[cmdlvl]);
  2308.     return(vvbuf);
  2309.  
  2310.       case VN_DATE:            /* DATE */
  2311.     ztime(&p);            /* Get "asctime" string */
  2312.     if (p == NULL || *p == NUL) return(NULL);
  2313.     vvbuf[0] = p[8];        /* dd */
  2314.     vvbuf[1] = p[9];
  2315.     vvbuf[2] = SP;
  2316.     vvbuf[3] = p[4];        /* mmm */
  2317.     vvbuf[4] = p[5];
  2318.     vvbuf[5] = p[6];
  2319.     vvbuf[6] = SP;
  2320.     for (x = 20; x < 24; x++)    /* yyyy */
  2321.       vvbuf[x - 13] = p[x];
  2322.     vvbuf[11] = NUL;
  2323.     return(vvbuf);
  2324.  
  2325.       case VN_NDAT:            /* Numeric date */
  2326.     ztime(&p);            /* Get "asctime" string */
  2327.     if (p == NULL || *p == NUL) return(NULL);
  2328.     for (x = 20; x < 24; x++)    /* yyyy */
  2329.       vvbuf[x - 20] = p[x];
  2330.         vvbuf[6] = (p[8] == ' ') ? '0' : p[8]; vvbuf[7] = p[9]; /* dd */
  2331.     for (x = 0; x < 12; x++)      /* mm */
  2332.       if (!strncmp(p+4,months[x],3)) break;
  2333.     if (x == 12) {
  2334.         vvbuf[4] = vvbuf[5] = '?';
  2335.     } else {
  2336.         x++;
  2337.         vvbuf[4] = (x < 10) ? '0' : '1';
  2338.         vvbuf[5] = (x % 10) + 48;
  2339.     }
  2340.     vvbuf[8] = NUL;
  2341.         return(vvbuf);
  2342.  
  2343.       case VN_DIRE:            /* DIRECTORY */
  2344.     return(zgtdir());
  2345.  
  2346.       case VN_FILE:            /* filespec */
  2347.     return(fspec);
  2348.  
  2349.       case VN_HOST:            /* host name */
  2350.     if (*myhost) {            /* If known */
  2351.         return(myhost);        /* return it. */
  2352.     } else {            /* Otherwise */
  2353.         strcpy(vvbuf,"unknown");    /* just say "unknown" */
  2354.         return(vvbuf);
  2355.     }
  2356.  
  2357.       case VN_SYST:            /* System type */
  2358. #ifdef UNIX
  2359.     strcpy(vvbuf,"UNIX");
  2360. #else
  2361. #ifdef VMS
  2362.     strcpy(vvbuf,"VMS");
  2363. #else
  2364. #ifdef OSK
  2365.     strcpy(vvbuf,"OS9/68K");
  2366. #else
  2367. #ifdef AMIGA
  2368.     strcpy(vvbuf,"Amiga");
  2369. #else
  2370. #ifdef MAC
  2371.     strcpy(vvbuf,"Macintosh");
  2372. #else
  2373. #ifdef OS2
  2374.     strcpy(vvbuf,"OS/2");
  2375. #else
  2376. #ifdef datageneral
  2377.     strcpy(vvbuf,"AOS/VS");
  2378. #else
  2379. #ifdef GEMDOS
  2380.     strcpy(vvbuf,"Atari_ST");
  2381. #else
  2382.     strcpy(vvbuf,"unknown");
  2383. #endif /* GEMDOS */
  2384. #endif /* datageneral */
  2385. #endif /* OS2 */
  2386. #endif /* MAC */
  2387. #endif /* AMIGA */
  2388. #endif /* OSK */
  2389. #endif /* VMS */
  2390. #endif /* UNIX */
  2391.     return(vvbuf);
  2392.  
  2393.       case VN_SYSV:            /* System herald */
  2394.     for (x = y = 0; x < VVBUFL; x++) {
  2395.         if (ckxsys[x] == SP && y == 0) continue;
  2396.         vvbuf[y++] = (ckxsys[x] == SP) ? '_' : ckxsys[x];
  2397.     }
  2398.     vvbuf[y] = NUL;
  2399.     return(vvbuf);
  2400.  
  2401.       case VN_TIME:            /* TIME. Assumes that ztime returns */
  2402.     ztime(&p);            /* "Thu Feb  8 12:00:00 1990" */
  2403.     if (p == NULL || *p == NUL)    /* like asctime()! */
  2404.       return(NULL);
  2405.     for (x = 11; x < 19; x++)    /* copy hh:mm:ss */
  2406.       vvbuf[x - 11] = p[x];        /* to vvbuf */
  2407.     vvbuf[8] = NUL;            /* terminate */
  2408.     return(vvbuf);            /* and return it */
  2409.  
  2410.       case VN_NTIM:            /* Numeric time */
  2411.     ztime(&p);            /* "Thu Feb  8 12:00:00 1990" */
  2412.     if (p == NULL || *p == NUL)    /* like asctime()! */
  2413.       return(NULL);
  2414.     z = atol(p+11) * 3600L + atol(p+14) * 60L + atol(p+17);
  2415.     sprintf(vvbuf,"%ld",z);
  2416.     return(vvbuf);
  2417.  
  2418. #ifdef UNIX
  2419.       case VN_TTYF:            /* TTY file descriptor */
  2420.     sprintf(vvbuf,"%d",ttyfd);
  2421.     return(vvbuf);
  2422. #else
  2423. #ifdef OS2
  2424.       case VN_TTYF:            /* TTY file descriptor */
  2425.     sprintf(vvbuf,"%d",ttyfd);
  2426.     return(vvbuf);
  2427. #endif /* OS2 */
  2428. #endif /* UNIX */
  2429.  
  2430.       case VN_VERS:            /* Numeric Kermit version number */
  2431.     sprintf(vvbuf,"%ld",vernum);
  2432.     return(vvbuf);
  2433.  
  2434.       case VN_HOME:            /* Home directory */
  2435. #ifdef UNIX
  2436.         sprintf(vvbuf,"%s/",zhome());
  2437.     return(vvbuf);
  2438. #else
  2439. #ifdef OSK
  2440.         sprintf(vvbuf,"%s/",zhome());
  2441.     return(vvbuf);
  2442. #else
  2443.     return(zhome());
  2444. #endif /* OSK */
  2445. #endif /* UNIX */
  2446.  
  2447.       case VN_IBUF:            /* INPUT buffer */
  2448.     return(inpbuf);
  2449.  
  2450.       case VN_ICHR:            /* INPUT character */
  2451.     inchar[1] = NUL;
  2452.     return((char *)inchar);
  2453.  
  2454.       case VN_ICNT:            /* INPUT character count */
  2455.         sprintf(vvbuf,"%d",incount);
  2456.     return(vvbuf);
  2457.  
  2458.       case VN_SPEE: {            /* Transmission SPEED */
  2459.       long t;
  2460.       t = ttgspd();
  2461.       if (t < 0L)
  2462.         sprintf(vvbuf,"unknown");
  2463.       else
  2464.         sprintf(vvbuf,"%ld",t);
  2465.       return(vvbuf);
  2466.       }
  2467.       case VN_SUCC:            /* SUCCESS flag */
  2468.     sprintf(vvbuf,"%d",(success == 0) ? 1 : 0);
  2469.     return(vvbuf);
  2470.  
  2471.       case VN_LINE:            /* LINE */
  2472.     p = (char *) ttname;
  2473.         return(p);
  2474.  
  2475.       case VN_PROG:            /* Program name */
  2476. #ifdef MAC
  2477.     return("Mac-Kermit");
  2478. #else
  2479.     return("C-Kermit");
  2480. #endif /* MAC */
  2481.  
  2482.       case VN_RET:            /* Value of most recent RETURN */
  2483.     p = mrval[maclvl+1];
  2484.     if (p == NULL) p = "";
  2485.     return(p);
  2486.  
  2487.       case VN_FFC:            /* Size of most recent file */
  2488.     sprintf(vvbuf, "%ld", ffc);
  2489.     return(vvbuf);
  2490.  
  2491.       case VN_TFC:            /* Size of most recent file group */
  2492.     sprintf(vvbuf, "%ld", tfc);
  2493.     return(vvbuf);
  2494.  
  2495.       case VN_CPU:            /* CPU type */
  2496. #ifdef CKCPU
  2497.     return(CKCPU);
  2498. #else
  2499.     return("unknown");
  2500. #endif /* CKCPU */
  2501.  
  2502.       case VN_CMDL:            /* Command level */
  2503.     sprintf(vvbuf, "%d", cmdlvl);
  2504.     return(vvbuf);
  2505.  
  2506.       case VN_DAY:            /* Day of week */
  2507.       case VN_NDAY:
  2508. /*
  2509.   Depends on ztime() returning ENGLISH asctime()-format string!
  2510.   asctime() format is: "Thu Feb  8 12:00:00 1990".
  2511.   Needs updating to accommodate non-English asctime() strings.
  2512. */
  2513.     ztime(&p);
  2514.     if (p != NULL && *p != NUL) {    /* ztime() succeeded. */
  2515.         if (y == VN_DAY) {        /* String day. */
  2516.         strncpy(vvbuf,p,3);
  2517.         } else {            /* Numeric day. */
  2518.         for (x = 0; x < 7; x++)      /* Look up day string in table */
  2519.           if (!strncmp(p,wkdays[x],3))
  2520.             break;
  2521.         if (x > 6) x = -1;    /* Not found */
  2522.         sprintf(vvbuf,"%d",x);    /* Return the number */
  2523.         }
  2524.     } else vvbuf[0] = NUL;        /* ztime() failed. */
  2525.     return(vvbuf);            /* Return what we got. */
  2526.  
  2527.       case VN_LCL:            /* Local (vs remote) mode */
  2528.     strcpy(vvbuf, local ? "1" : "0");
  2529.     return(vvbuf);
  2530.  
  2531.       case VN_CMDS:            /* Command source */
  2532.     if (cmdstk[cmdlvl].src == CMD_KB)
  2533.       strcpy(vvbuf,"prompt");
  2534.     else if (cmdstk[cmdlvl].src == CMD_MD)
  2535.       strcpy(vvbuf,"macro");
  2536.     else if (cmdstk[cmdlvl].src == CMD_TF)
  2537.       strcpy(vvbuf,"file");
  2538.     else strcpy(vvbuf,"unknown");
  2539.     return(vvbuf);
  2540.  
  2541.       case VN_CMDF:            /* Current command file name */
  2542. #ifdef COMMENT                /* (see comments above) */
  2543.     if (tfnam[tlevel]) {        /* (near dblbs declaration) */
  2544.         dblbs(tfnam[tlevel],vvbuf,VVBUFL);
  2545.         return(vvbuf);
  2546.     } else return("");
  2547. #else
  2548.     if (tlevel < 0)
  2549.       return("");
  2550.     else
  2551.       return(tfnam[tlevel] ? tfnam[tlevel] : "");
  2552. #endif
  2553.  
  2554.       case VN_MAC:            /* Current macro name */
  2555.     return((maclvl > -1) ? m_arg[maclvl][0] : "");
  2556.  
  2557.       case VN_EXIT:
  2558.     sprintf(vvbuf,"%d",xitsta);
  2559.     return(vvbuf);
  2560.  
  2561.       default:
  2562.     return(NULL);
  2563.     }
  2564. }
  2565. #endif /* NOSPL */
  2566.  
  2567. /*
  2568.   X X S T R I N G  --  Expand variables and backslash codes.
  2569.  
  2570.     int xxtstring(s,&s2,&n);
  2571.  
  2572.   Expands \ escapes via recursive descent.
  2573.   Argument s is a pointer to string to expand (source).
  2574.   Argument s2 is the address of where to put result (destination).
  2575.   Argument n is the length of the destination string (to prevent overruns).
  2576.   Returns -1 on failure, 0 on success,
  2577.     with destination string null-terminated and s2 pointing to the
  2578.     terminating null, so that subsequent characters can be added.
  2579. */
  2580.  
  2581. #define XXDEPLIM 100            /* Recursion depth limit */
  2582.  
  2583. int
  2584. xxstring(s,s2,n) char *s; char **s2; int *n; {
  2585.     int x,                /* Current character */
  2586.         y,                /* Worker */
  2587.         pp,                /* Paren level */
  2588.         argn,                /* Function argument counter */
  2589.         n2,                /* Local copy of n */
  2590.         d,                /* Array dimension */
  2591.         vbi,                /* Variable id (integer form) */
  2592.         argl;                /* String argument length */
  2593.  
  2594.     char vb,                /* Variable id (char form) */
  2595.         *vp,                /* Pointer to variable definition */
  2596.         *new,                /* Local pointer to target string */
  2597.         *p,                /* Worker */
  2598.         *q;                /* Worker */
  2599.     char *r  = (char *)0;        /* For holding function args */
  2600.     char *r2 = (char *)0;
  2601.  
  2602. #ifndef NOSPL
  2603.     char vnambuf[VNAML];        /* Buffer for variable/function name */
  2604.     char *argp[FNARGS];            /* Pointers to function args */
  2605. #endif /* NOSPL */
  2606.  
  2607.     static int depth = 0;        /* Call depth, avoid overflow */
  2608.  
  2609.     n2 = *n;                /* Make local copies of args */
  2610.     new = *s2;                /* for one less level of indirection */
  2611.  
  2612.     depth++;                /* Sink to a new depth */
  2613.     if (depth > XXDEPLIM) {        /* Too deep? */
  2614.     printf("?definition is circular or too deep\n");
  2615.     depth = 0;
  2616.     *new = NUL;
  2617.     return(-1);
  2618.     }
  2619.     if (!s || !new) {            /* Watch out for null pointers */
  2620.     depth = 0;
  2621.     *new = NUL;
  2622.     return(-1);
  2623.     }
  2624.     argl = (int)strlen(s);        /* Get length of source string */
  2625.     debug(F111,"xxstring",s,argl);
  2626.     if (argl < 0) {            /* Watch out for garbage */
  2627.     depth = 0;
  2628.     *new = NUL;
  2629.     return(-1);
  2630.     }
  2631.     while ( x = *s ) {            /* Loop for all characters */
  2632.         if (x != CMDQ) {        /* Is it the command-quote char? */
  2633.         *new++ = *s++;        /* No, normal char, just copy */
  2634.         if (n2-- < 0) {        /* and count it, careful of overflow */
  2635.         return(-1);
  2636.         }
  2637.         continue;
  2638.     }
  2639.  
  2640. /* We have the command-quote character. */
  2641.  
  2642.     x = *(s+1);            /* Get the following character. */
  2643.     switch (x) {            /* Act according to variable type */
  2644. #ifndef NOSPL
  2645.       case '%':            /* Variable */
  2646.         s += 2;            /* Get the letter or digit */
  2647.         vb = *s++;            /* and move source pointer past it */
  2648.         vp = NULL;            /* Assume definition is empty */
  2649.         if (vb >= '0' && vb <= '9') { /* Digit for macro arg */
  2650.         if (maclvl < 0)     /* Digit variables are global */
  2651.           vp = g_var[vb];    /* if no macro is active */
  2652.         else            /* otherwise */
  2653.           vp = m_arg[maclvl][vb - '0']; /* they're on the stack */
  2654.         } else {
  2655.         if (isupper(vb)) vb -= ('a'-'A');
  2656.         vp = g_var[vb];        /* Letter for global variable */
  2657.         }
  2658.         if (vp) {            /* If definition not empty */
  2659.         if (xxstring(vp,&new,&n2) < 0) { /* call self to evaluate it */
  2660.             return(-1);        /* Pass along failure */
  2661.         }
  2662.         }
  2663.         break;
  2664.       case '&':            /* An array reference */
  2665.         if (arraynam(s,&vbi,&d) < 0) { /* Get name and subscript */
  2666.         return(-1);
  2667.         }
  2668.         pp = 0;            /* Bracket counter */
  2669.         while (*s) {        /* Advance source pointer */
  2670.         if (*s == '[') pp++;
  2671.         if (*s == ']' && --pp == 0) break;
  2672.         s++;
  2673.         }
  2674.         if (*s == ']') s++;        /* past the closing bracket. */
  2675.         if (chkarray(vbi,d) > 0) {    /* Array is declared? */
  2676.         vbi -= 96;        /* Convert name to index */
  2677.         if (a_dim[vbi] >= d) {    /* If subscript in range */
  2678.             char **ap;
  2679.             ap = a_ptr[vbi];    /* get data pointer */
  2680.             if (ap) {        /* and if there is one */
  2681.             if (ap[d]) {    /* If definition not empty */
  2682.                 if (xxstring(ap[d],&new,&n2) < 0) { /* evaluate */
  2683.                 return(-1); /* Pass along failure */
  2684.                 }
  2685.             }
  2686.             }
  2687.         }
  2688.         }
  2689.         break;
  2690.  
  2691.       case 'F':            /* A builtin function */
  2692.       case 'f':
  2693.         q = vnambuf;        /* Copy the name */
  2694.         y = 0;            /* into a separate buffer */
  2695.         s+=2;            /* point past 'F' */
  2696.         while (y++ < VNAML) {
  2697.         if (*s == '(') { s++; break; } /* Look for open paren */
  2698.         if ((*q = *s) == NUL) break;   /* or end of string */
  2699.         s++; q++;
  2700.         }
  2701.         *q = NUL;            /* Terminate function name */
  2702.         if (y >= VNAML) {        /* Handle pathological case */
  2703.         while (*s && (*s != '(')) /* of very long string entered */
  2704.           s++;              /* as function name. */
  2705.         if (*s == ')') s++;      /* Skip past it. */
  2706.         }
  2707.         r = r2 = malloc(argl+2);    /* And make a place to copy args */
  2708.         debug(F101,"xxstring r2","",r2);
  2709.         if (!r2) {            /* Watch out for malloc failure */
  2710.         depth = 0;
  2711.         *new = NUL;
  2712.         return(-1);
  2713.         }
  2714.         argn = 0;            /* Argument counter */
  2715.         argp[argn++] = r;        /* Point to first argument */
  2716.         y = 0;            /* Completion flag */
  2717.         pp = 1;            /* Paren level (already have one). */
  2718.         while (*r = *s) {        /* Copy each argument, char by char. */
  2719.         if (*r == '(') pp++;    /* Count an opening paren. */
  2720.         if (*r == ')') {    /* Closing paren, count it. */
  2721.             if (--pp == 0) {    /* Final one? */
  2722.             *r = NUL;    /* Make it a terminating null */
  2723.             s++;
  2724.             y = 1;        /* Flag we've got all the args */
  2725.             break;
  2726.             }
  2727.         }
  2728.         if (*r == ',') {    /* Comma */
  2729.             if (pp == 1) {    /* If not within ()'s, */
  2730.             *r = NUL;        /* new arg, skip past it, */
  2731.             argp[argn++] = r+1; /* point to new arg. */
  2732.             if (argn == FNARGS) /* Too many args */
  2733.               break;
  2734.             }            /* Otherwise just skip past  */
  2735.         }
  2736.         s++; r++;        /* Advance pointers */
  2737.         }
  2738.         debug(F110,"xxstring function name",vnambuf,0);
  2739.         if (!y) {            /* If we didn't find closing paren */
  2740.         debug(F101,"xxstring r2 before free","",r2);
  2741.         if (r2) free(r2);    /* free the temporary storage */
  2742.         return(-1);        /* and return failure. */
  2743.         }
  2744. #ifdef DEBUG
  2745.         if (deblog)
  2746.           for (y = 0; y < argn; y++)
  2747.         debug(F111,"xxstring function arg",argp[y],y);
  2748. #endif /* DEBUG */
  2749.         vp = fneval(vnambuf,argp,argn); /* Evaluate the function. */
  2750.         if (vp) {            /* If definition not empty */
  2751.         while (*new++ = *vp++)    /* copy it to output string */
  2752.           if (n2-- < 0) return(-1); /* mindful of overflow */
  2753.         new--;            /* Back up over terminating null */
  2754.         n2++;            /* to allow for further deposits. */
  2755.         }
  2756.         if (r2) {
  2757.         debug(F101,"xxstring freeing r2","",r2);
  2758.         free(r2);        /* Now free the temporary storage */
  2759.         r2 = NULL;
  2760.         }
  2761.         break;
  2762.       case '$':            /* An environment variable */
  2763.       case 'V':            /* Or a named builtin variable. */
  2764.       case 'v':
  2765.       case 'M':            /* Or a macro = long variable */
  2766.       case 'm':
  2767.         p = s+2;            /* $/V/M must be followed by (name) */
  2768.         if (*p != '(') {        /* as in \$(HOME) or \V(count) */
  2769.         *new++ = *s++;        /* If not, just copy it */
  2770.         if (n2-- < 0) {
  2771.             return(-1);
  2772.         }
  2773.         break;
  2774.         }
  2775.         p++;            /* Point to 1st char of name */
  2776.         q = vnambuf;        /* Copy the name */
  2777.         y = 0;            /* into a separate buffer */
  2778.         while (y++ < VNAML) {    /* Watch out for name too long */
  2779.         if (*p == ')') {    /* Name properly terminated with ')' */
  2780.             p++;        /* Move source pointer past ')' */
  2781.             break;
  2782.         }
  2783.         if ((*q = *p) == NUL)    /* String ends before ')' */
  2784.           break;
  2785.          p++; q++;        /* Advance pointers */
  2786.         }
  2787.         *q = NUL;            /* Terminate the variable name */
  2788.         if (y >= VNAML) {        /* Handle pathological case */
  2789.         while (*p && (*p != ')')) /* of very long string entered */
  2790.           p++;              /* as variable name. */
  2791.         if (*p == ')') p++;      /* Skip ahead to the end of it. */
  2792.         }
  2793.         s = p;            /* Adjust global source pointer */
  2794.         p = malloc((int)strlen(vnambuf) + 1); /* Make temporary space */
  2795.         if (p) {            /* If we got the space */
  2796.         vp = vnambuf;        /* Point to original */
  2797.         strcpy(p,vp);        /* Make a copy of it */
  2798.         y = VNAML;        /* Length of name buffer */
  2799.         xxstring(p,&vp,&y);    /* Evaluate the copy */
  2800.         free(p);        /* Free the temporary space */
  2801.         }
  2802.         debug(F110,"xxstring vname",vnambuf,0);
  2803.         if (x == '$') {        /* Look up its value */
  2804.         vp = getenv(vnambuf);    /* This way for environment variable */
  2805.         } else if (x == 'm' || x == 'M') { /* or this way for macro */
  2806.         y = mlook(mactab,vnambuf,nmac);    /* contents (= long variable */
  2807.         vp = (y > -1) ? mactab[y].mval : ""; /* name)... */
  2808.         } else {             /*  or */
  2809.             vp = nvlook(vnambuf);    /* this way for builtin variable */
  2810.         }
  2811.         if (vp) {            /* If definition not empty */
  2812.         while (*new++ = *vp++)    /* copy it to output string. */
  2813.           if (n2-- < 0) {
  2814.             return(-1);
  2815.         }
  2816.         new--;            /* Back up over terminating null */
  2817.         n2++;            /* to allow for further deposits. */
  2818.         }
  2819.         break;
  2820. #endif /* NOSPL    */            /* Handle \nnn even if NOSPL. */
  2821.       default:            /* Maybe it's a backslash code */
  2822.         y = xxesc(&s);        /* Go interpret it */
  2823.         if (y < 0) {        /* Upon failure */
  2824.         *new++ = x;        /* Just quote the next character */
  2825.         s += 2;            /* Move past the pair */
  2826.         n2 -= 2;
  2827.         if (n2 < 0) {
  2828.             return(-1);
  2829.         }
  2830.         continue;        /* and go back for more */
  2831.         } else {
  2832.         *new++ = y;        /* else deposit interpreted value */
  2833.         if (n2-- < 0) {
  2834.             return(-1);
  2835.         }
  2836.         }
  2837.     }
  2838.     }
  2839.     *new = NUL;                /* Terminate the new string */
  2840.     depth--;                /* Adjust stack depth gauge */
  2841.     *s2 = new;                /* Copy results back into */
  2842.     *n = n2;                /* the argument addresses */
  2843.     return(0);                /* and return. */
  2844. }
  2845. #endif /* NOICP */
  2846.